[ { _id: 'r1nJZ96Al',
    cardID: '44',
    name: 'wcc',
    job: 'sofeware',
    phone: '18068591822',
    depart: 'develop',
    status: true,
    __v: 0 },
  { _id: 'H1RZ-qaRx',
    cardID: '33',
    name: 'zss',
    job: 'sofeware',
    phone: '3534645645',
    depart: 'develop',
    status: true,
    __v: 0 }]
形如上面的数组,模板引擎用的jade,前端框架angularjs。
我直接用jade中的each可正确遍历出数组数据,
但是用ng-repeat="a in data"(data代表上面的数组数据)
a.name无法遍历出数据,并提示Cannot read property 'name' of undefined为何

解决方案 »

  1.   

    应该不会有这样的情况,感觉上是data没有被放进$scope。
      

  2.   

    extends layoutblock content
        #container(ng-app='myApp',ng-controller='EmpListCtrl')
            #head
                .logo
                    h1 丰巨泰科BIM工地人员管理系统
                .nav
                    ul
                        li
                            a.cur(href='') 首页
                  
                .blank
            #main
                #left
                    .admin
                        .head
                            img(src='./images/head.gif', alt='')
                        .intro
                            p.role 角色:管理员
                            p.name 姓名:朱沙沙
                            p.job 职位:研发工程师
                    .subnav
                        ul
                            li
                                a.cur(href='') 员工列表
                          
                #right
                    .guide
                        p 所有员工列表
                    .emp_list
                        table.t_emp
                            caption 丰巨泰科BIM工地员工列表
                            thead
                                tr
                                    th(width='15%') 工号
                                    th(width='15%') 姓名
                                    th(width='15%') 职位
                                    th(width='15%') 联系方式
                                    th(width='15%') 所属部门
                                    th(width='15%') 状态
                                    th(width='10%')
                            tbody
                                    tr(ng-repeat='x ind emps')
                                        td #{x.name}            script.
                    var app = angular.module('myApp', []);
                    app.controller('EmpListCtrl', function ($scope) {
                        $scope.emps = emps;                });两位帮忙看下那
      

  3.   

    代码中有个地方敲错了,x in emps,但是修改后依然无效
      

  4.   

    /* GET employee inforamation*/
    module.exports.emp_list = function (req,res) {    // find emp_list from mongodb,and send data to emp_list template
        var ss = empdb.findAll().then(function (data) {
            console.info(data);
            res.render('emp_list',{'emps':data});
        },function (err) {
            console.error(err);
        });
    }这是controller代码,很简单
      

  5.   

    data没有被放进$scope。
      

  6.   

    试试 使用console.log(emps)检查一下数据来源,有可能混了一条无效的数据,比如空记录之类的
      

  7.   


    做了个最简单的测试
      tbody(ng-controller='EmpListCtrl')
                                    tr(ng-repeat='x in emps')
                                        td   #{x}            script.
                    var app = angular.module('myApp', []);
                    app.controller('EmpListCtrl', function ($scope) {
                        $scope.emps = ['a','b','c','d'];
                        $scope.title = "sss";
                    });数据直接写死,读出#{title}没问题,但是遍历不出emps
      

  8.   

    你这个简单的测试,最终生成的html,看一下,里面有没有什么问题,是不是jad出问题了?
      

  9.   

     我试了一下,你的jade代码可能写错了,我用当前版本的pug编译你的测试代码,结果是:
    <tbody ng-controller="EmpListCtrl"><tr ng-repeat="x in emps"><td></td></tr></tbody>
    显然是不对的,你的#{x},被jade作为参数处理了。我改成
    tbody(ng-controller='EmpListCtrl')
        tr(ng-repeat='x in emps')
            td {{x}}
    编译以后结果
    <tbody ng-controller="EmpListCtrl"><tr ng-repeat="x in emps"><td>{{x}}</td></tr></tbody>这个才是正确的第一次接触jade,没有注意到语法问题,误导了,不好意思。
      

  10.   

                   tbody
                                    tr
                                        td   #{arr}            script.
                    var app = angular.module('myApp', []);
                    app.controller('EmpListCtrl', function ($scope) {
                        $scope.emps = [{name:'yueyue',sex:'man'},{name:'zss',sex:'man'},{name:'aaaa',sex:'man'},{name:'bbbb',sex:'man'}];
                        $scope.title = 'ssssss';
                        $scope.test = function () {
                            alert("ddddddddddddd");
                        }
                    });我把数组放到$scope中ng-repeat没有问题,现在的关键是res.render('index',{title:'zss'})过来的参数,比如title,能否放在$scope里面?如何被$scope接收
      

  11.   

    <ul ng-app="myApp" ng-controller="myCtrl">
    <li ng-repeat="x in names">
    {{x}}
    </li>
    </ul>
    <script>
    var app = angular.module("myApp",[]);
    app.controller("myCtrl",function($scope,$http){
    $http({
    method:"get",
    url:"",
    dataType:"json",
    }).success(function(data){
    var obj = eval(data);
    $scope.names = obj;
    }).error(function(msg){

    });
    });
    </script>