我正在尝试用两个不同的对象进行重复。在这种情况下,我想返回“名称:Leanne Graham,姓名:Asier ”。 JSON文件有这个。
users: {
0: {
email: "Sincere@april.biz",
id: 1,
name: "Leanne Graham",
phone: "1-770-736-8031 x56442",
username: "Bret",
website: "hildegard.org"
},
1: {
name: "Asier"
}
};
有两个对象的元素是$ scope.user,我试试这个
<div ng-repeat="(key, value) in user">{{name}}</div>
没有任何反应,并且console.log中没有错误。
答案 0 :(得分:1)
如果您的数据实际上是有效的格式,重复该集合似乎很简单......
// note: this is just an example to put your data in scope
angular.module('so', []).run(function($rootScope) {
$rootScope.user = {
0: {
email: "Sincere@april.biz",
id: 1,
name: "Leanne Graham",
phone: "1-770-736-8031 x56442",
username: "Bret",
website: "hildegard.org"
},
1: {
name: "Asier"
}
};
});
<div ng-app="so">
<div ng-repeat="usr in user">{{usr.name}}</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>