1

我正在测试 angularJS。

在 app.js 我有

function ListCtrl($scope, Restangular) {
   Restangular.all("employee").getList().then(function(employee) {
     $scope.employee = employee;
     console.log($scope.employee.emp);
   });
}

在html中我有

<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Emp No</th>
<th>Name</th>
<th><a href="#/new"><i class="icon-plus-sign"></i></a></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee | filter:search | orderBy:'ename'">
<td><a href="{{employee.empno}}" target="_blank">{{employee.empno}}</a>
</td>
<td>{{employee.ename}}</td>
<td>
<a href="#/edit/{{employee.ename}}"><i class="icon-pencil"></i></a>
</td>
</tr>
</tbody>
</table>

我面临的问题是显示空行而没有显示数据。这可能是什么原因?

编辑 1

从服务器返回的 JSON

{"emp":[{"empno":"7369","ename":"SMITH","hiredate":
"1980-12-17T00:00:00+03:00","job":"CLERK","mgr":"7902","sal":"800"},
{"comm":"300","empno":"7499","ename":"ALLEN","hiredate":
"1981-02-20T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1600"},
{"comm":"500","empno":"7521","ename":"WARD","hiredate":
"1981-02-22T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1250"},
{"empno":"7566","ename":"JONES","hiredate":
"1981-04-02T00:00:00+03:00","job":"MANAGER","mgr":"7839","sal":"2975"},
{"comm":"1400","empno":"7654","ename":"MARTIN","hiredate":
"1981-09-28T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1250"},
{"empno":"7698","ename":"BLAKE","hiredate":
"1981-05-01T00:00:00+03:00","job":"MANAGER","mgr":"7839","sal":"2850"},
{"empno":"7782","ename":"CLARK","hiredate":
"1981-06-09T00:00:00+03:00","job":"MANAGER","mgr":"7839","sal":"2450"},
{"empno":"7788","ename":"SCOTT","hiredate":
"1987-04-19T00:00:00+03:00","job":"ANALYST","mgr":"7566","sal":"3000"},
{"empno":"7839","ename":"KING","hiredate":
"1981-11-17T00:00:00+03:00","job":"PRESIDENT","sal":"5000"},
{"comm":"0","empno":"7844","ename":"TURNER","hiredate":
"1981-09-08T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1500"}]}

来自 Chrome 浏览器的控制台日志

[Object, Object, Object, Object, Object, Object, Object, Object, 
Object, Object, Object, Object, Object, Object, route: "employee",
getRestangularUrl: function, addRestangularMethod: function, one:
function, all: function…]
0: Object
empno: "7369"
ename: "SMITH"
hiredate: "1980-12-17T00:00:00+03:00"
job: "CLERK"
mgr: "7902"
sal: "800"
4

1 回答 1

3

根据您包含的 JSON,它看起来$scope.employee应该包含一个名为“emp”的键,这是您打印到控制台的内容。您可能需要更改您的 ng-repeat 才能使用它。

另外,我不熟悉您的 ng-repeat 表达式的形式。我相信他们应该遵循类似于“某事中的某事”的形式,所以在这种情况下,而不是只是employee你可能希望那样employee in employee.emp

在更一般的意义上,Chrome 的Angular Batarang 插件对于解决这类问题非常有帮助。

于 2013-11-25T19:21:57.037 回答