gpt4 book ai didi

javascript - Angularjs 在当前行位置添加行

转载 作者:行者123 更新时间:2023-11-28 00:26:47 25 4
gpt4 key购买 nike

我有以下代码,假设在当前行位置添加另一行(而不是在行的底部):

<tr ng-repeat="ro in rows">
<td>{{ro.name}}</td>
<td>{{ro.id}}</td>
<td><a ng-click="addRo($index)">add row</a></td>
</tr>

在我的 Controller 中,我有:

$scope.addRo=function(index){
$scope.inderted={
id: '',
name: ''
};
$scope.rows($index+1).push($scope.inserted);
}

我尝试了上面的代码,希望将索引添加到当前位置,它会添加它,但它不起作用。如何解决这个问题?

最佳答案

尝试使用.splice()而不是.push()

$scope.addRo=function(index){
var inderted={
id: '',
name: ''
};
$scope.rows.splice(index + 1, 0, inderted);
}

这是docs对于 .splice()

此外,如果您只是暂时使用它,则无需将“inderted”添加到范围中。

关于javascript - Angularjs 在当前行位置添加行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29421362/

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