Angular UI 树:获取节点的新旧父节点

Angular UI Tree: Get old and new parent of node

我创建了两棵树,当我将一个节点从一棵树移动到另一棵树时,我想知道旧树和新树的名称。我在 ui-tree 中添加了 data-tree-name="unsorted" 但我不知道如何访问它。这是我的代码:

        <div ui-tree="treeOptions" data-tree-name="unsorted">
            <ol ui-tree-nodes="" ng-model="skill.unsorted">
                <li ng-repeat="sk in skill.unsorted" ui-tree-node>
                    <div ui-tree-handle>
                        @{{ sk.name }}
                    </div>
                </li>
            </ol>
        </div>

         <div ui-tree="treeOptions" data-tree-name="sorted">
            <ol ui-tree-nodes="" ng-model="category">
                <li ng-repeat="cat in category" ui-tree-node>
                    <div ui-tree-handle>
                        @{{ cat.name }}
                    </div>
                    <ol ui-tree-nodes="" ng-model="cat.skills">
                        <li ng-repeat="sk in cat.skills" ui-tree-node>
                            <div ui-tree-handle>
                                @{{ sk.name }}
                            </div>
                        </li>
                    </ol>
                </li>
            </ol>
        </div>
----------------------------------------------------
$scope.treeOptions = {
        accept: function(sourceNodeScope, destNodesScope, destIndex) {
            return true;
        },
        dropped: function(e) {
            console.log (e.source.nodeScope);
        }
    };

那么我怎样才能得到 data-tree-name 值。谢谢

参见官方文档中dropped事件的文档:

下降(事件)

如果节点在下降后移动它的位置,将调用 nodeDropped 回调。

参数:

  • event: Event arguments, it's an object.

    • source: Source object

      • nodeScope: The scope of source node which was dragged.

      • nodesScope: The scope of the parent nodes of source node when it began to drag.

      • index: The position when it began to drag.

      • cloneModel: Given data-clone-enabled is true, holds the model of the cloned node that is to be inserted, this can be edited before drop without affecting the source node.

    • dest: Destination object

      • nodesScope: The scope of ui-tree-nodes which you just dropped in.

      • index: The position you dropped in.

    • elements: The dragging relative elements.

      • placeholder: The placeholder element.

      • dragging: The dragging element.

    • pos: Position object.

这是一个例子:

$scope.treeOptions = {
    dropped: function(event) {
        var sourceNode = event.source.nodeScope;
        var destNodes = event.dest.nodesScope;
        var sortBefore = event.source.index + 1;
        var sortAfter = event.dest.index + 1;
        var dataType = destNodes.$element.attr('data-type');

        // ...
    }
};