angular不会显示范围变量(完成)

时间:2016-03-24 19:32:22

标签: javascript angularjs angularjs-scope jstree

我正在使用jstree和angularjs。我有节点的路径和名称,但无法在页面上显示。我的错误在哪里?我已经用我的问题用ng-tree指令更新了plunker(工作)示例。现在它非常接近我的应用程序

我也在这里提供了plunker的代码

Html:

 <h1>Where is my variable?!</h1>
         <div>{{ test }}</div>
  <pre>Path to A: {{ pathA }}</pre>
   <pre>Path to B: {{ pathB }}</pre>
      <pre>Path to C:{{ pathC }}</pre>
<js-tree tree-data="json" tree-src="tree.json"
                   tree-events="changed:callback;"></js-tree>

Js

$scope.test = "I'm test variable"

    $scope.callback = function (e, data) {

        // ===== Click event on node for Industry =====
        for (var i = 0; i < data.selected.length; i++) {

            var parentNodeId = data.instance.get_node(data.selected[i]).parent;
            var parentNodeText = data.instance.get_node(parentNodeId).text;
            var selectedNodes = data.instance.get_selected();

            var node = data.instance.get_node(data.selected[i]).text;

            console.log(node);

            if (node == "a"){
                     console.log($scope.pathA)
             $scope.pathA  = data.instance.get_path(data.node,'/');

            }
             else if (node == "b"){
                 console.log($scope.pathA)
              $scope.pathB  = data.instance.get_path(data.node,'/');

            }
             else if (node == "c"){
               console.log($scope.pathA)
             $scope.pathC  = data.instance.get_path(data.node,'/');

            }
            // and etc....
        }
    }

1 个答案:

答案 0 :(得分:2)

您的jstree不会导致任何更改检测,这意味着回调也不会,并且您的所有变量都不会更新。您可以通过在回调中手动调用$scope.$apply()来解决此问题!