ztree 异步加载 点击展开出现undefined

发布于 2021-12-06 22:28:06 字数 2187 浏览 846 评论 2

@zTree 你好,想跟你请教个问题:

ztree 异步加载 点击展开出现undefined

 

function dataSourceInit(dType) {
  var postData = {
    host: Dvm.host,
    type: dType,
    level: 0,
    name: dType === 0 ? "本地磁盘文件" : "数据库",
    absoluteName: '/'
  };
  Dvm.buDataType =postData.name;
  angular.element("#treeDisplay .root_close").on('click', function(){
    angular.element(".ztree li").css({'background': 'url(assets/images/loading.gif) no-repeat','z-index':'9999'});
    angular.element("#treeDisplay .root_close").css({'background-position':'-60px -54px'});
  });
  BackupService.getDataSource(postData).then(function(result){
    var resData = result.data.data;
     for(var k=0,klen=resData.children.length;k<klen;k++) {
       resData.children[k].isParent = true;
     }
    $.fn.zTree.init($("#tree"), tree.setting, resData);
    var treeObj = $.fn.zTree.getZTreeObj("tree");
    var nodes = treeObj.getNodes();
    var checkNodes = treeObj.getNodesByFilter(filter);
    var getTrees = treeObj.getNodes()[0].children;
    angular.element("#tree").css({'display':'block'});
    angular.element("#treeDisplay").css({'display':'none'});
    for(var j=0,len1=nodeSource.length;j<len1;j++){
      for(var i=0,len=getTrees.length;i<len;i++) {
        if(getTrees[i].absoluteName===nodeSource[j]){
          getTrees[i].checked = true;
        }
      }
    }
    if (nodes.length>0) {
      for(var i=0;i<nodes.length;i++){
        treeObj.expandNode(nodes[i], true, false, false);
      }
    }
    treeObj.updateNode(treeObj.treeNode);
    //禁用CheckBox
    for(var i=0;i<checkNodes.length;i++) {
      var node = checkNodes[i];
      node.nocheck = false;
      treeObj.updateNode(node);
    }
  }, function(msg) {
    console.log(msg);
  });
}

function filter(node) {
  node.chkDisabled = true;
  return node;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2021-12-08 22:03:46
{"data":{
"id":"0-10.142.20.83-0-/",
"name":"本地磁盘文件",
"absoluteName":"/",
"level":0,
"type":0,
"parentId":null,
"host":"10.142.20.83",
"children":[{"id":"amanda/","name":"amanda/","absoluteName":"/amanda/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"bin/","name":"bin/","absoluteName":"/bin/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"boot/","name":"boot/","absoluteName":"/boot/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"chenleilei/","name":"chenleilei/","absoluteName":"/chenleilei/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"data/","name":"data/","absoluteName":"/data/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"dev/","name":"dev/","absoluteName":"/dev/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"ect/","name":"ect/","absoluteName":"/ect/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"eisoo/","name":"eisoo/","absoluteName":"/eisoo/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"etc/","name":"etc/","absoluteName":"/etc/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"guanhaiyan/","name":"guanhaiyan/","absoluteName":"/guanhaiyan/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"home/","name":"home/","absoluteName":"/home/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"lc/","name":"lc/","absoluteName":"/lc/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"lib/","name":"lib/","absoluteName":"/lib/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"lib64/","name":"lib64/","absoluteName":"/lib64/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"media/","name":"media/","absoluteName":"/media/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"mnt/","name":"mnt/","absoluteName":"/mnt/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"Mysqldata/","name":"Mysqldata/","absoluteName":"/Mysqldata/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"opt/","name":"opt/","absoluteName":"/opt/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"proc/","name":"proc/","absoluteName":"/proc/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"recovery/","name":"recovery/","absoluteName":"/recovery/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"root/","name":"root/","absoluteName":"/root/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"run/","name":"run/","absoluteName":"/run/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"sbin/","name":"sbin/","absoluteName":"/sbin/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"srv/","name":"srv/","absoluteName":"/srv/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"sys/","name":"sys/","absoluteName":"/sys/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"sysvol/","name":"sysvol/","absoluteName":"/sysvol/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"tmp/","name":"tmp/","absoluteName":"/tmp/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"usr/","name":"usr/","absoluteName":"/usr/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null},
{"id":"var/","name":"var/","absoluteName":"/var/","level":1,"type":0,"parentId":"","host":"10.142.20.83","children":null}]},
"errorMessage":null,
"hasErrors":false,
"success":true}
  var tree = {
    zTree:'',
    pNode:'',
    setting : {
      showLine : true,                  //是否显示节点间的连线
      check: {
        enable: true,
        autoCheckTrigger: true
      },
      async:{
        enable: true, //采用异步加载
        dataFilter: ajaxFilter
      },
      root:{
        isRoot:true,
        nodes:[]
      },
      data: {
        key: {
          name: "name"
        },
        simpleData: {
          enable: true,
          idKey: "id",
          pidKey: "parentId",
        }
      },
      callback: {
        beforeClick: zTreeBeforeClick,
        onExpand: zTreeOnExpand,
        onCheck: onCheck
      }
    }
  };

数据结构没有问题啊,请看下

清晨说ぺ晚安 2021-12-07 17:03:25

检查数据结构吧

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文