1

現在、ノードを作成し、Angular Tree Control がノードをレンダリングするプロジェクトに取り組んでいます。たとえば、ノードを作成したり、ノードを注文したり (ツリー内を上下に移動) した場合、ツリーを更新して、ツリー内の最後のノードを選択する必要があります。

このドキュメントの例を使用しようとしました: http://wix.github.io/angular-tree-control/が、ツリーが更新されません。

これは私のコードです。

意見:

<div ng-controller="TreeController">
                <treecontrol class="tree-light"
                             name="rik"
                             tree-model="dataForTheTree"
                             options="treeOptions"
                             on-selection="showSelected(node)"
                             order-by="orderby"
                             selected-node="selected">
                </treecontrol>
            </div>

角度:

angular.module('recursionDemo', ['treeControl'])
        .controller("TreeController", ['$scope', '$http', function ($scope, $http) {
            $scope.dataForTheTree = [];

            $scope.showSelected = function(node)
            {
            $scope.treeOptions = {
                nodeChildren: "children",
                dirSelectable: true,
                injectClasses: {
                    ul: "a1",
                    li: "a2",
                    liSelected: "a7 tree-li-expanded-light",
                    iExpanded: "",
                    iCollapsed: "",
                    iLeaf: "a5",
                    label: "a6",
                    labelSelected: "a8"
                }
            }
            $http.get('/ajax/nodes')
                .success(function(data) {
                    $scope.dataForTheTree = data;
                    $scope.selected = 240; //select Node 240
                })
        }])
        .controller("NodeMoveController", ['$scope', '$http', function ($scope, $http) {
            $scope.NodeMove = function() {
               var move_to_node         = $('.move_to_node').val();
                var current_node    = $('.current_node').val()
                // ajax call
                $.ajax({
                    type : "POST",
                    headers: { 'X-XSRF-TOKEN' : token },
                    url : "/ajax/node/move",
                    data : {
                        move_to_node : move_to_node,
                        current_node : current_node
                    }
                }).done(function(msg) {
                // get new Nodes
                $http.get('/ajax/nodes')
                    .success(function(data) {
                        $scope.dataForTheTree = data;
                      // go to selected Node in the tree
                      $scope.selected = $scope.dataForTheTree[240]; // for example hardcoded 240 instead of msg.current_node
                    })
                });
            }
        }]);

しかし、コードのこの部分を使用すると: $scope.selected = $scope.dataForTheTree[240]; ツリーが更新されておらず、ノード 240 が選択されています。

このツリー コントロールを使用した経験のある人はいますか、それともこれを達成するための他のオプションはありますか?

前もって感謝します!

4

0 に答える 0