0

我试图在我的项目中使用带有延迟加载的 dynatree。当我尝试将选择功能与复选框结合起来并选择模式 3 时,我很失望地看到模式 3 的选择规则是选择包括子项在内的所有内容 .... 选择父项时的子项。这是因为孩子们还没有被加载。

有没有人有办法让这个工作?我将非常感谢任何建议。赞!

4

2 回答 2

0

诚然,以下内容有点小技巧......但它解决了这个问题:

onSelect: function (flag, node) {
    if (flag && node.childList == undefined) {
        node.reloadChildren(function() {
            node.select(false);
            node.select(true);
        });
    }

如果正在选择节点(标志 == true)并且尚未加载节点(childList == undefined),则使用回调函数调用 reloadChildren。回调在数据加载后运行,并简单地关闭/打开复选框。这会导致选择所有子节点(现在存在)。

于 2013-03-01T06:29:15.790 回答
0

添加您选择的父母的孩子时,请检查父母是否有孩子。如果为 TRUE,则添加每个子项并将这些子项中的每一个设置为选中。

下面是一些代码。将onLazyRead上升。每次点击惰性节点时,都会触发此功能。在这个函数内部应该调用你的函数来获取你刚刚选择的节点的子数据。

下面的代码是我解决这个问题的方法。它所做的几乎所有事情都是检查您添加的节点的父节点是否被选中。如果为 TRUE,则添加节点,然后添加.select()它。

这在取消选择节点时要简单得多,因为所有节点都已加载。取消选择时,只需从被取消选择的节点向下走树的层次​​结构,然后简单地取消选中每个节点。

我知道这有很多代码可以扔给你,但希望你能从中领悟到这个想法。如果你不能,我会在工作期间尝试返回这个线程。也许您甚至可以发布到目前为止的内容?

onLazyRead: function(node){

jQuery("#tree2").dynatree("getTree").disable();

        var pParentID = node.data.key;          

                    //Select the Node

        doChildReport(pParentID); //Get Children for this node's ID

    },


///....
//Methods to grab data from a "XMLHttpRequest GET" go here
//....

//When you finally want to add the children that you fetched using the ID of the node you selected...

//treeArray is an array of node data that has been parsed out of a 
//string returned by a "XMLHttpRequest GET"

//Contents of array in order, repeating: treeArray[0] = ParentID, [1] = nodeID [2] = nodeName
//Example, the array would return [111], [222], ["Child Node"]


if(){ //IF Next fetched node is on the last level, ie. no children
            //add normally
        }
    else{  //If NOT, add lazy.
        if(treeArray[1] != "nill" && treeArray[1] != undefined){

        //IF THE PARENT NODE IS SELECTED
        if(jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[0]).isSelected() == true){

        //AND IF the child node does not exist
        if(jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[1]) == null){

            //Add the child node and then mark it selected
            addChildNodeLazy(treeArray[1], treeArray[2], treeArray[0]);
            jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[1]).select();
        }   
        }else{
            if( jQuery("#tree2").dynatree("getTree").getNodeByKey(treeArray[1]) == null){
                addChildNodeLazy(treeArray[1], treeArray[2], treeArray[0]);
            }
        }
    }
}

延迟加载功能...

function addChildNodeLazy(NodeID, NodeName, ParentID){
        jQuery("#tree2").dynatree("getTree").getNodeByKey(ParentID).addChild({title: NodeName, key: NodeID, icon: false, isFolder: true, isLazy: true});
    }
于 2012-10-17T13:07:25.603 回答