【发布时间】:2013-11-19 13:02:32
【问题描述】:
我有一个 sortable-wrapper 指令,它允许在列表中移动项目以及从一个列表移动到另一个。
使用数组容器:
$scope.container = [
[{id: '1.1'}, {id: '1.2'}, {id: '1.3'}],
[{id: '2.1'}, {id: '2.2'}, {id: '2.3'}]
]
我使用这样的指令:
<div ng-repeat="array in container">
<ul sortable>
<li ng-repeat="item in array">{{ item.id }}</li>
</ul>
</div>
当一个项目被放入列表时,我必须更新项目后端并将后端返回的移动项目插入到正确的数组/索引中:
$scope.move = function (from, fromIndex, to, toIndex) {
$http.post(url, data).success(function(movedItem) {
from.splice(fromIndex, 1)[0];
to.splice(toIndex, 0, movedItem);
});
}
此指令在 1.2.0-rc.2 版本之前运行良好,因为 1.2.0-rc.3 在移动项目时出现此错误:
TypeError: Cannot call method 'insertBefore' of null
at http://code.angularjs.org/1.2.1/angular.js:3857:22
at forEach (http://code.angularjs.org/1.2.1/angular.js:303:18)
at Object.enter (http://code.angularjs.org/1.2.1/angular.js:3856:9)
at http://code.angularjs.org/1.2.1/angular.js:18828:26
at publicLinkFn (http://code.angularjs.org/1.2.1/angular.js:5443:29)
at boundTranscludeFn (http://code.angularjs.org/1.2.1/angular.js:5555:21)
at controllersBoundTransclude (http://code.angularjs.org/1.2.1/angular.js:6145:18)
at ngRepeatAction (http://code.angularjs.org/1.2.1/angular.js:18826:15)
at Object.$watchCollectionAction [as fn] (http://code.angularjs.org/1.2.1/angular.js:11347:11)
at Scope.$digest (http://code.angularjs.org/1.2.1/angular.js:11443:27)
这是一个重现错误的 plunker:http://plnkr.co/edit/bAD8z2KdW34a7hkhdyiu?p=preview
有什么想法吗?
【问题讨论】:
标签: javascript jquery-ui angularjs jquery-ui-sortable