嵌套的重复,一个依赖于另一个

nested ng-repeat that one depend on the other

本文关键字:一个 依赖于 另一个 嵌套      更新时间:2023-09-26

我有一个问题与角,我想在数据表中使用两个嵌套的ng-repeat,其中第一个获得数据,第二个获得要从数据中检索的字段名称(在第一个ng-repeat中检索)
下面是我尝试做的代码:

<table md-table flex-order-gt-sm >
  <thead md-head>
    <tr md-row >
   //1st : get the name of fields, not a problem
        <th md-column ng-repeat="field in fields">{{item.name}}</th>
            </tr>
    </thead>
    <tbody md-body>
       <tr md-row ng-repeat="item in items">
            <td md-cell ng-repeat="field in fields" >
   //here is the problem I want to get the item that it's field name is field
                     {{item.{{field}} }}</td>
                </tr>
            </tbody>
        </table>

例如,如果字段包含:{'a','b','c'}
条目包含{'a':'1','b':'2','c':'3'};
例如,对于{{item的第一次迭代。{{字段}}}}返回1

使用toString()检索作用域对象中的作用域数据

<tr md-row ng-repeat="item in items">
    <td md-cell ng-repeat="field in fields" >
        {{item[field.toString()]}}
    </td>
</tr>

这是活塞

作为一种选择,你也可以使用过滤器:

<td md-cell ng-repeat="field in fields | filter: { name: 'field' }">                
</td>

您需要根据项目收集后的项目获取字段收集

getFieldsByItem(项目)

那么你可以从fields集合中获取字段{{领域}}