gpt4 book ai didi

javascript - 嵌套 ng-repeat 一个依赖于另一个

转载 作者:行者123 更新时间:2023-12-02 14:05:01 25 4
gpt4 key购买 nike

我有 Angular 问题,我想在数据表中使用两个嵌套的 ng-repeat,其中第一个获取数据,第二个获取要从数据中检索的字段名称(在第一个 ng 中检索) -重复)
这是我尝试使用代码执行的操作:

<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.{{field}} }} 的第一次迭代返回 1

最佳答案

使用toString()检索范围对象中的范围数据。

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

Here is the plunker

关于javascript - 嵌套 ng-repeat 一个依赖于另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40128610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com