【发布时间】:2017-04-11 07:18:05
【问题描述】:
我一直试图在远程 JSON 文件的表中显示对象字段,如 name、address。我似乎无法弄清楚我做错了什么。 ng-repeat 仅在我索引迭代器时有效。
angular.module('mainApp', [])
.controller('branchListCtrl', function($scope, $http) {
$http.get('http://some.url.com')
.then(function(response) {
$scope.artists = response.data;
console.log($scope.artists);
});
});
<tr ng-repeat="x in artists">
<td>{{x.name}}</td> <!--this only gives empty rows equal to # of objectsin json-->
<td>{{x.address}}</td>
</tr>
<tr ng-repeat="x in artists">
<td>{{x[1].name}}</td>
<td>{{x[1].address}}</td>
</tr>
【问题讨论】:
-
添加json结构
-
{ "success":"yes", "data":[ { "id":"1", "parent_retailer":1, "name":"dummy", "address":" 1234d", "status":true, "geo_location":{ "x":24.321, "y":74.102 } }, { "id":"2", "parent_retailer":1, "name":"dummy2" , "地址":"fdsds", "状态":true, "geo_location":{ "x":24.321, "y":74.102 } }, ], "error_code":"", "error_description":"" }
-
研究你的 JSON。可能使用jsonformatter.curiousconcept.com 来重构(美化)你的JSON,然后理解它的结构。你会得到你的答案。
标签: angularjs json angularjs-ng-repeat