繁体   English   中英

在AngularJs中使用JSON进行ng-repeat

[英]ng-repeat with JSON in AngularJs

我有一个JSON

{"uuid":"5634","day":"three","one":{},"two":{},"three":{"people":[{"name":"sam","count":"2"},{"name":"das","count":"5"},{"name":"smith","count":"12"},]}}

我只想重复键“三”中的数据。 是否可以将其映射为“ day”值?

在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];

然后通过如下修改ng-repeat在视图中使用该变量:

<div ng-repeat="person in dayData.people">
  <h1>{{ person.name }}</h1>
  <p>Count : {{ person.count }}</p>
</div>

样例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM