【发布时间】:2018-07-13 13:32:27
【问题描述】:
TL;DR;
我需要拖入嵌套列表,但无法正常工作。我在Plunkr 编译了一个简单的示例。
我有没有定义深度的动态嵌套集,我只需要能够在它们自己的父容器中对它们进行排序。但是由于父母也被拖着走,所以每当你拿起一个孩子时,整棵树都被拖着走。
function ListItemController($scope, dragulaService) {
var self = this;
this.$onInit = function() {
dragulaService.options( $scope, this.item.id, {
removeOnSpill: false,
moves: function (el, source, handle, sibling) {
console.info(el, target, source, sibling);
return el.id === self.item.id; // elements are always draggable by default
},
accepts: function (el, target, source, sibling) {
console.info(el, target, source, sibling);
return true; // elements can be dropped in any of the `containers` by default
},
invalid: function (el, handle) {
return el.id !== self.item.id; // don't prevent any drags from initiating by default
},
});
if (this.item.children && this.item.children.length > 0) {
$scope.$on(this.item.id + '.drag', function() {
console.info(this.item.id + '.drag', arguments);
});
}
};
}
documentation 提到使用moves 函数创建一个句柄,这可能会帮助我,但我从来没有从那个函数得到日志,也没有从accepts 函数得到日志。
我尝试使用$postLink 和$scope.$$dragula 上的观察者来确保它被启动,甚至是dragulaService.find($scope, self.item.id) 上的观察者。都没有用...
【问题讨论】:
标签: angularjs dragula angular-dragula