1
我是AngularJS的新手。angularJS:帶數據結構的同步重新排序列表
我正在嘗試使用Angular ui-sortable插件重新排列數組。我希望數據數組與html ul的順序相同,但似乎無法成功。
var myapp = angular.module('myapp', ['ui']);
myapp.controller('controller', function ($scope) {
$scope.sortableOptions = {
start: function (e, ui) {
$scope.oldIndex = ui.item.index();
},
update: function (e, ui) {
var newIndex = $scope.newIndex = ui.item.index();
var oldIndex = $scope.oldIndex;
$scope.oldArray = $scope.list.join(';');
var item = $scope.list.splice(oldIndex, 1);
$scope.list.splice(newIndex, 0, item[0]);
$scope.itemMoved = item;
$scope.newArray = $scope.list.join(';');
}
}
$scope.list = ["one", "two", "three", "four", "five", "six"];
});
angular.bootstrap(document, ['myapp']);
任何想法?
小提琴: http://jsfiddle.net/DxjXQ/2/