gpt4 book ai didi

javascript - AngularJS:通过字段名称获取数组值

转载 作者:行者123 更新时间:2023-12-03 11:10:05 26 4
gpt4 key购买 nike

在我的第一个 Angular 应用程序中,我有这样的数据:

tree_rows = [{"level":1,"branch":{"Name":"USA","Area":9826675,"Population":318212000,"TimeZone":"UTC -5 to -10","children":[{"Name":"California","Area":423970,"Population":38340000,"TimeZone":"Pacific Time","children":[{"Name":"San Francisco","Area":231,"Population":837442,"TimeZone":"PST"},{"Name":"Los Angeles","Area":503,"Population":3904657,"TimeZone":"PST"}]},{"Name":"Illinois","Area":57914,"Population":12882135,"TimeZone":"Central Time Zone","children":[{"Name":"Chicago","Area":234,"Population":2695598,"TimeZone":"CST"}]}],"level":1,"expanded":true,"uid":"0.5810681234579533","Options":[]},"label":"USA","tree_icon":"icon-file glyphicon glyphicon-file fa fa-file","visible":true},{"level":1,"branch":{"Name":"Texas","Area":268581,"Population":26448193,"TimeZone":"Mountain","level":1,"expanded":true,"uid":"0.8260199765209109","Options":[]},"label":"Texas","tree_icon":"icon-file glyphicon glyphicon-file fa fa-file","visible":true}]

colDefinitions = [{"field":"Area"},{"field":"Population"},{"field":"TimeZone"},{"field":"children"}]

我尝试通过 table-grid-view 查看它:

<tr ng-repeat=\"row in tree_rows | filter:{visible:true} track by row.branch.uid\"
ng-class=\"'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')\" class=\"tree-grid-row\">
<td class=\"text-primary\"><a ng-click=\"user_clicks_branch(row.branch)\"><i ng-class=\"row.tree_icon\"
ng-click=\"row.branch.expanded = !row.branch.expanded\"
class=\"indented tree-icon\"></i>
</a><span class=\"indented tree-label\" ng-click=\"user_clicks_branch(row.branch)\">
{{row.branch[expandingProperty]}}</span>
</td>
<td ng-repeat=\"col in colDefinitions\">{{row.branch[col.field]}}</td> - this line!!!
</tr>

一切都很好,只是我不想将所有数据显示为:<td ng-repeat=\"col in colDefinitions\">{{row.branch[col.field]}}</td>但例如 {{row.branch[Name]}} , {{row.branch[Population]}}在那里我没有看到任何数据。但为什么呢?

如何通过字段从数组中获取数据?

ps:我用这个:https://github.com/khan4019/tree-grid-directive/blob/master/README.md

最佳答案

尝试使用 {{row.branch["Name"]}} 代替,引用字段名称

关于javascript - AngularJS:通过字段名称获取数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27637607/

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