zTree / zTree_v3

jQuery Tree Plugin
MIT License
4.1k stars 1.28k forks source link

使用 reAsyncChildNodes 报错 Uncaught TypeError: Cannot read property 'tId' of null #429

Closed charrysong closed 4 years ago

charrysong commented 4 years ago

addHoverDom 的 元素 onclick 事件中 reAsyncChildNodes `

var setting = { async: { enable: true, url: "org_node.ashx", autoParam: ["id", "pId", "name"] }, data: { simpleData: { enable: true } }, view: { showIcon: false, dblClickExpand: false, txtSelectedEnable: false, addHoverDom: addHoverDom, removeHoverDom: removeHoverDom, addDiyDom: addDiyDom,//添加自定义菜单 }, edit: { drag: { autoExpandTrigger: false, isMove: false, isCopy: false, }, enable: false, editNameSelectAll: false, showRemoveBtn: false, showRenameBtn: false, removeTitle: "删除", renameTitle: "重命名" } }; 

function nodeclick(obj, id, pid) {

        if (pid == null) { }

       else {
            let treeObj = $.fn.zTree.getZTreeObj("treeDemo");

            let node = treeObj.getNodeByParam("id", pid, null);

            treeObj.reAsyncChildNodes(node, "refresh", false, function () { });

        }

}

var setting = { async: { enable: true, url: "org_node.ashx", autoParam: ["id", "pId", "name"] }, data: { simpleData: { enable: true } }, view: { showIcon: false, dblClickExpand: false, txtSelectedEnable: false, addHoverDom: addHoverDom, removeHoverDom: removeHoverDom, addDiyDom: addDiyDom,//添加自定义菜单 }, edit: { drag: { autoExpandTrigger: false, isMove: false, isCopy: false, }, enable: false, editNameSelectAll: false, showRemoveBtn: false, showRenameBtn: false, removeTitle: "删除", renameTitle: "重命名" } };

function addHoverDom(treeId, treeNode) {

        var node = $("#" + treeNode.tId + "_a");

        if (node.find('.node_up').length == 0) {

            node.append(“<span title=\"更新当前父节点下的子节点\" class=\"ui_btn node_up\" onclick=\"nodeclick(this,” + treeNode.id + “," + treeNode.pId + ")\"><i class=\"ico up\"></i></span>");

        }

    };

` TIM截图20191120101625

zTree commented 4 years ago

请再仔细查找一下错误的位置,这是在 selectNode 时报错的,但你的代码里面有没有调用 selectNode 方法,应该是你调用 selectNode 方法时,没有传入 zTree 内部的节点数据

charrysong commented 4 years ago

请再仔细查找一下错误的位置,这是在 selectNode 时报错的,但你的代码里面有没有调用 selectNode 方法,应该是你调用 selectNode 方法时,没有传入 zTree 内部的节点数据

节点的数据能重新加载,但是就是报这个错误 TIM截图20191121114206

zTree commented 4 years ago

你的逻辑有问题呀!! 点击 节点A 的时候,你却要去重新加载 A 的父节点的 子节点,这样会导致 A 节点被删除,但与此同时, zTree 还会因为 点击 A节点,要进行选中 A节点的操作,所以就出现这个错误了!