gpt4 book ai didi

javascript - 嵌套的 ng-repeat 无法正常工作

转载 作者:行者123 更新时间:2023-11-30 00:15:43 24 4
gpt4 key购买 nike

我试图调用一个双重嵌套的 ng-repeat 来循环遍历对象中的对象,但它不起作用。我正在使用表 (tr, td)

这是我的 HTML 代码:

<tr ng-repeat="row in rows">
<td ng-repeat="item in row">
{{item}}
</td>
</tr>

这是我的数据对象:

$scope.rows = [["10:00", "0"],["12:00","1"]]

但是表格没有打印任何东西。我做错了什么?谢谢!

更新

stackoverflow 示例工作正常,抱歉。

对于我的数据,原始数组不起作用:

[["10:00","0","0","3","0","0","0","0"],    
["12:00","0","0","3","0","0","0","0"],
["14:00","0","0","3","0","0","0","0"],
["16:00","0","0","3","0","0","0","0"],
["18:00","0","0","3","0","0","0","0"],
["20:00","0","0","3","0","0","0","0"],
["22:00","0","0","3","0","0","0","0"]]

我想创建这样的东西:

enter image description here

最佳答案

当完全按照所示使用示例数据运行代码时,控制台日志中会记录以下错误:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in row, Duplicate key: string:0, Duplicate value: 0

这可以通过将 track by 表达式添加到您的 ng-repeat 来解决。由于您没有数据中的特定列用作索引,因此您可以使用 ng-repeat$index 特殊属性。

<tr ng-repeat="row in rows">
<td ng-repeat="item in row track by $index">
{{item}}
</td>
</tr>

此代码将为您提供预期的输出。

http://plnkr.co/edit/aSbaom85JsQwUfTIwKk3?p=preview

关于javascript - 嵌套的 ng-repeat 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34801768/

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