當用戶單擊時刪除按鈕在第一個列表中我需要刪除項目並在第二個列表中添加相同的項目。使用angularjs添加和刪除陣列問題中的項目
當用戶單擊第二個列表中的添加按鈕時,我需要刪除第二個列表中的項目並添加到第一個列表中。
但問題是當我點擊「Berglundssnabbköp」項目添加到第二個列表,但刪除第一個項目。
HTML:
<b>First one</b>
<ul>
<li ng-repeat="x in records|orderBy:x">{{x}}
<input type="button" ng-click="del(x)" value="Delete">
</li>
</ul>
<hr>
<b>Second one</b>
<ul>
<li ng-repeat="x in details|orderBy:x">{{x}}
<input type="button" ng-click="add(x)" value="ADD">
</li>
</ul>
腳本:
$scope.del=function(item){
alert(item);
$scope.details.push(item);
$scope.records.splice(item,1);
};
$scope.add=function(item){
alert(item);
$scope.records.push(item);
$scope.details.splice(item,1);
};
http://jsfiddle.net/halirgb/Lvc0u55v/
什麼是「Berglundssnabbköp」? – azad
你的JSFiddle與你的問題不匹配 – Phil
@azad我想象它是'$ scope.records'中的條目之一(但不是第一個) – Phil