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