简体   繁体   English

对对象angularjs进行ng-repeat

[英]ng-repeat on object angularjs

I have an object like this 我有一个这样的物体

Obj = {
  "elements":[
               {"name":"something","id":"v1-234"},
               {"name":"somethingElse","id":"v1-239"}
             ],
  "paging":{
    "next" : "100",
    "total": "2000"  
   },
 "linked"={
            "partners":[
                         {"id":"82","name":"A"},
                         {"id":"83","name":"B"}
                       ],
             "instructors":
                       [
                         {"id":"11232","name":"alex"},
                         {"id":"11432","name":"boob"}
                       ]
           }
    }

I have equal items inside the elements array and the partner and instructors array. 我在elements数组和partner和教师数组中有相等的项。 I have only placed 2 items just for display there could be many. 我只放置了2个项目只是为了显示,可能有很多。

The Obj.elements[0] is related to Obj.linked.partners[0] and Obj.linked.instructors[0]. Obj.elements [0]与Obj.linked.partners [0]和Obj.linked.instructors [0]相关。 Similarly for the first,second,third ..... items as well. 同样,第一,第二,第三项也是如此。

How can I ng-repeat on this object such that I can show 如何对这个对象进行ng-repeat以便显示

Obj.elements[i] Obj.linked.partners[i] Obj.linked.instructors[i] Obj.elements [i] Obj.linked.partners [i] Obj.linked.instructors [i]

at a time in html template ? 一次在html模板中?

If your elements, partners, and instructors arrays will always be the same length and you wanted to for example join together the names you could try something like this. 如果您的元素,合作伙伴和讲师数组的长度始终相同,并且您想例如将名称结合在一起,则可以尝试这样的操作。

<div ng-repeat="element in Obj.elements">
    {{element.name}} {{Obj.linked.partners[$index].name}} {{Obj.linked.instructors[$index].name}}
</div>

$index is used by Angular in a ng-repeat to keep track of its position when iterating through an object. Angular在ng-repeat中使用$ index来跟踪对象迭代时的位置。 Here is the documentation: ng-repeat 这是文档: ng-repeat

ng-repeat has the $index scoped variable: ng-repeat具有$index范围变量:

<ANY ng-repeat="element in model.elements">
   <span ng-bind="element.name"></span>
   <span ng-bind="model.linked.partners[$index].name"></span>
   <span ng-bind="model.linked.instructors[$index].name"></span>
</ANY>

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

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