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

时间:2021-05-15 23:03:12

I'm working with jstree and angularjs. I've got path and name of nodes but cannot display it on a page. Where is my mistake? I have updated plunker(working) example with ng-tree directive with my problem. Now it's pretty close to my app

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

also I provide the code of plunker here

我也在这里提供了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 个解决方案

#1


2  

Your jstree isn't causing any change detection, which means that the callback won't either and none of your variables will get updated. You can fix this by manually calling $scope.$apply() in the callback!

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

#1


2  

Your jstree isn't causing any change detection, which means that the callback won't either and none of your variables will get updated. You can fix this by manually calling $scope.$apply() in the callback!

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