Angular JS代碼。 2列表,每個列表有內部的項目,點擊列表中的一個項目,該項目從列表中刪除,並添加到另一個Angular JS編碼問題
尋找可重用性:
$scope.move=function(index){
$scope.list2.push($scope.list1[index]);
$scope.list1.splice(index,1);
}
Angular JS代碼。 2列表,每個列表有內部的項目,點擊列表中的一個項目,該項目從列表中刪除,並添加到另一個Angular JS編碼問題
尋找可重用性:
$scope.move=function(index){
$scope.list2.push($scope.list1[index]);
$scope.list1.splice(index,1);
}
這是易如反掌:https://plnkr.co/edit/xxTpvxB9GSwAqy25s5GN?p=preview
<body ng-controller="MainCtrl">
<p>List1</p>
<div ng-repeat="item in list1">
<a href="" ng-click="move($index);">{{item}}</a>
</div>
<hr/>
<p>List2</p>
<div ng-repeat="item in list2">{{item}}</div>
</body>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.list1 = [
"12",
"13",
"14"
];
$scope.list2=["223"];
$scope.move=function(index){
$scope.list2.push($scope.list1[index]);
$scope.list1.splice(index,1);
}
});
歡迎來到StackOverflow。請查看幫助菜單,瞭解有關提問或不提問以及如何提問的問題。 StackOverflow不是代碼猴子的社區。 –