からスプライスのために選択を削除するために、インデックスを使用し、foreachの中に二番目の引数を追加します助けてください、私のコントローラのコード
$scope.tableArray=[]
$scope.tableslist=[]
$scope.getTable=function(table){
table.btnClass = table.btnClass == "btn-danger" ? "btn-success" : "btn-danger"
console.log(table)
var exists=false;
angular.forEach($scope.tableArray, function (list) {
if ((list.tablename == table.tablename)) {
console.log(list.tablename)
console.log(table.tablename)
exists=true;
$scope.tableArray.splice(list._id,1)
return false
}
});
if(!exists){
$scope.tableslist.push(table)
$scope.tableArray=$scope.tableslist
console.log($scope.tableArray)
table.color="red"
}
}
です配列内のアイテムは、下記のようにindexOfを使用できます。
$scope.tableArray.splice($scope.tableArray.indexOf(list),1);
ありがとうございます。私のために働く。 – SrinivasAppQube