I have a JSON
我有一个JSON
{"uuid":"5634","day":"three","one":{},"two":{},"three":{"people":[{"name":"sam","count":"2"},{"name":"das","count":"5"},{"name":"smith","count":"12"},]}}
I want to repeat only the data from the key "three". Is it possible to map that with the value "day"?
我想只重复键“三”中的数据。是否可以使用“日”值映射?
1 个解决方案
#1
5
In your Controller, derive a new $scope
variable for the data you wish to use in your view:
在Controller中,为您希望在视图中使用的数据派生一个新的$ scope变量:
var data = {"uuid":"5634","day":"three","one":{},"two":{},"three":{"people":[{"name":"sam","count":"2"},{"name":"das","count":"5"},{"name":"smith","count":"12"},]}};
$scope.dayData = data[data.day];
Then use that variable in your view by amending the ng-repeat
as follows:
然后通过修改ng-repeat在视图中使用该变量,如下所示:
<div ng-repeat="person in dayData.people">
<h1>{{ person.name }}</h1>
<p>Count : {{ person.count }}</p>
</div>
示例Plunk
#1
5
In your Controller, derive a new $scope
variable for the data you wish to use in your view:
在Controller中,为您希望在视图中使用的数据派生一个新的$ scope变量:
var data = {"uuid":"5634","day":"three","one":{},"two":{},"three":{"people":[{"name":"sam","count":"2"},{"name":"das","count":"5"},{"name":"smith","count":"12"},]}};
$scope.dayData = data[data.day];
Then use that variable in your view by amending the ng-repeat
as follows:
然后通过修改ng-repeat在视图中使用该变量,如下所示:
<div ng-repeat="person in dayData.people">
<h1>{{ person.name }}</h1>
<p>Count : {{ person.count }}</p>
</div>
示例Plunk