
{{item.id}}
{{item.name}}
{{item.quantity}}
{{item.price}}
{{item.quantity * item.price}}
一下是JS部分:
$scope.remove = function (ids) {
var index = -1;
//console.log(ids);
angular.forEach($scope.cart, function (item,key) {
console.log(key);
if(item.id===ids){
index =key;
}
if(index!==-1){
$scope.cart.splice(index,1);
}
});
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
既然你决定通过 index 来删除数据,为何不传入
$index作为参数呢?至于为什么会出现多次删除的情况,我是这么分析的:既然多次删除,一定是因为多次执行了
splice。而执行splice只有一个原因,就是index !== -1。所以,对于你当前的代码,
splice之后,至少需要把index设回 -1。或者跳出forEach循环。这样就不会删除多个了