AngularJS树控件选择节点绑定

时间:2016-04-18 21:55:08

标签: angularjs treeview treecontrol

目前我正在开发一个创建节点的项目,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。

有没有人有过使用Tree Control的经验,还是有其他选择来实现这个目标?

提前致谢!

0 个答案:

没有答案