我必须在使用Angular JS制作的表上显示JSON数组值。当我加载页面时调用Web服务并获取JSON数组。直到这里一切都很好,但是,当我想在视图上显示值时,我什么都没得到。我做的就像我之前做的那样,不知道为什么它不起作用。
有控制器:
assets.controller('DetallTipusCtrl', function ($scope, $http, $routeParams){
$http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/'+$routeParams.param).success(function(data) {
$scope.atrb = data;
});
$scope.param = $routeParams.param;
});
观点:
<table class="table" ng-controller="DetallTipusCtrl">
<tr>
<th>#</th>
<th><a href="">Atribut</a></th>
<th><a href="">Mida</a></th>
<th><a href="">Tipus</a></th>
</tr>
<tr ng-repeat="atribut in atrb | orderBy:sortField:reverse">
<td></td>
<td>{{atribut.nomAtribut}}</td>
<td>{{atribut.midaAtribut}}</td>
<td>{{atribut.valor}}</td>
</tr>
</table>
JSON数组构造得很好但我什么也看不见,我不知道为什么,如果有人可以提供帮助..谢谢!
编辑: JSON:
{"nomAtribut":"fgdsgsfd","midaAtribut":"16","valor":"String","tipus_actius_idtipus_actius":"26","nom":"yiuhdfiau837629875wf"}
解决:
JSON数组是一个JSON对象,这就是我如何迭代并显示属性:
<tr ng-repeat="(key, value) in atrb">
<td>{{value.propertie}}</td>
</tr>
答案 0 :(得分:3)
您的回复不是数组,而是一个对象。您可以迭代这样的对象属性:
<tr ng-repeat="(key, value) in atrb">
<td>{{value}}</td>
</tr>
如果您需要有条件地显示属性,可以检查密钥。
答案 1 :(得分:0)
您应该在成功函数中执行此操作
$http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/'+$routeParams.param).success(function(data) {
$scope.$evalAsync(function(){$scope.atrb = data;});
});
答案 2 :(得分:0)
使$http
调用如:
$http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/'+$routeParams.param)
.then(function(response) {$scope.atrb = response.data;});
答案 3 :(得分:0)
您的回复不是数组
<td>{{atrb.nomAtribut}}</td>
<td>{{atrb.midaAtribut}}</td>
<td>{{atrb.valor}}</td>
显示使用上面的代码