简体   繁体   English

AngularJS:对象的ng-repeat数组

[英]Angularjs: ng-repeat array of objects

in angularjs i want show a table with two columns: the header of the first column is "Type" and the second column is "Product". 在angularjs中,我想显示一个包含两列的表:第一列的标题为“ Type”,第二列为“ Product”。

In the controller i have the following structure (in the chrome debugger): 在控制器中,我具有以下结构(在chrome调试器中):

products: Array[0]
    drink:Array[12]
      0: Object
      1: Object
      ....
      ....

So i have a "products" array with "drink" key with associate an array of objects (12 items) 所以我有一个带有“ drink”键的“ products”数组,并关联了一个对象数组(12个项目)

In angularjs, with ng-repeats, how can i show as many rows as the number of products items (and show in the Type column the "drink" key) and in the column Product all the objects (only the name) associated with the key? 在angularjs中,使用ng-repeats,我如何显示与产品项数一样多的行(并在“类型”列中显示“饮料”键)以及在“产品”列中显示与该产品关联的所有对象(仅名称)键?

Thanks 谢谢

Instead of id and name put the attribute name which your object have: 代替idname放置对象具有的属性名称:

<table>
<tr ng-repeat="obj in products[0].drink">
<td>{{ obj.id}}</td>
<td>{{ obj.name}}</td>
</tr>
</table>

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

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