【发布时间】:2014-06-01 19:10:02
【问题描述】:
我正在尝试从 AngularJS 中的 json 生成 HTML 表。 我收到格式如下的 JSON:
我获取数据的服务如下所示:
customAPI.getUsers = function() {
return $http({
method: 'JSONP',
url: 'http://arka.foi.hr/WebDiP/2013_projekti/WebDiP2013_069/api/admin/users.php'
});
};
该代码的控制器看起来像这样
controller('usersController', function($scope, customAPIservice) {
$scope.filterName = null;
$scope.usersList = [];
/*Search*/
$scope.searchFilter = function(user) {
var keyword = new RegExp($scope.filterName, 'i');
return !$scope.filterName || keyword.test(user.korisnici.korisnik_ime) || keyword.test(user.korisnici.korisnik_prezime);
};
customAPIservice.getUsers().success(function(response) {
$scope.usersList = response.korisnici;
});
});
我的观点是这样的:
<input type="text" ng-model="nameFilter" placeholder="Trazi..."/>
<h2 >Korisnici</h2>
<table>
<thead>
<tr>
<th colspan="6">Korisnici sustava</th>
</tr>
<th>Surname</th>
</thead>
<tbody>
<tr ng-repeat="user in usersList| filter: searchFilter">
<td>{{$index + 1}}</td>
<td>{{user.korisnik.korisnik_prezime}}</td>
<td>{{user.korisnik.korisnik_username}}</td>
</tr>
<tr ng-show="usersList == ''">
<td colspan="5">
<img src="img/ajax-loader.gif" />
</td>
</tr>
</tbody>
</table>
我想我在将数据与视图绑定的地方搞砸了,但我对 Angular 还是很陌生,所以我找不到问题所在。另外我在网上查了一下,找不到任何东西。请帮忙。
【问题讨论】:
-
在您的控制器中,您有
customAPIservice,但您的服务定义为customAPI -
是的,我知道,但这只是服务 js 的一部分,所以这些东西可以工作,因为我收到 JSON 响应,用它制作表格是个问题
标签: javascript json angularjs angularjs-scope angularjs-ng-repeat