gpt4 book ai didi

javascript - ng重复:dupes Error when entering nulls in array

转载 作者:行者123 更新时间:2023-12-02 22:19:35 26 4
gpt4 key购买 nike

如何在 JavaScript 数组中输入连续的空值?

我无法理解如何在 JS 数组中输入连续的空值。这是我的工作脚本:

var myApp = angular.module("myApp", []);

myApp.controller("myCtrl", function($scope) {
$scope.items = [];
$scope.items[0] = [,,"this doesn't work"];
$scope.items[0] = [null,"this works"];
$scope.items[1] = [null,,"this works"];
$scope.items[2] = [null,null,"this doesn't work"];
$scope.items[3] = [null,,,"this doesn't work"];
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<table>
<tr ng-repeat="row in items">
<td ng-repeat="column in row">{{column}}</td>
</tr>
</table>
</div>
</body>

最佳答案

问题似乎在于如何输出 Angular ng-repeat 中的值。更改代码以使用 track by 来处理重复值。

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

关于javascript - ng重复:dupes Error when entering nulls in array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59274539/

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