<tr ng-repeat="item in cart"> <td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.quantity}}</td>
<td>{{item.price}}</td>
<td>{{item.quantity * item.price}}</td>
<td>
<button type="button" ng-click="remove(item.id)" class="btn btn-danger">移除</button>
</td>一下是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);
}
});
}
用angularJS做購物車清單點移除時總移除兩條數據?
呼如林
2018-09-13 09:11:51