嗨我有JSONObject,如下所示:
$scope.controls = {"fields":[{"id":1,"name":"Sales Figures 2017","area":"sales","value":"1800"},{"id":2,"name":"Are you on commission","area":"support","value":"Yes"}]}
我正在尝试循环并显示如下所示的结果,但只需要" name"和"价值"值。
输出就像
以下是我所做的只获取键和值,但它没有显示任何内容。
<div ng-repeat="key in controls">
{{key.name}} : {{key.value}}
</div>
答案 0 :(得分:2)
您必须访问控件对象中的fields
,因为那是阵列所在的位置。
<div ng-repeat="key in controls.fields">
{{key.name}} : {{key.value}}
</div>
答案 1 :(得分:1)
从fields
ng-repeat
媒体资源
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.controls = {"fields":[{"id":1,"name":"Sales Figures 2017","area":"sales","value":"1800"},{"id":2,"name":"Are you on commission","area":"support","value":"Yes"}]}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-repeat="key in controls.fields">
{{key.name}} : {{key.value}}
</div>
</div>