Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tree dijit树无法从collapase树获取子级_Tree_Dojo_Children - Fatal编程技术网

Tree dijit树无法从collapase树获取子级

Tree dijit树无法从collapase树获取子级,tree,dojo,children,Tree,Dojo,Children,我的道场树很大。我需要一次扩展一个节点以提高性能。我的树有复选框。当检查父节点时,我需要知道父节点的所有子节点,以及直到树叶的子节点。由于树未展开,我无法使用下面的代码获取子级 onClick: function(item, node) { var childTreeNode = node.getChildren(); } 在这种情况下,如何获取子级和子级详细信息 下面的fiddle链接包含该树 HTML代码: <div id="contentHere">

我的道场树很大。我需要一次扩展一个节点以提高性能。我的树有复选框。当检查父节点时,我需要知道父节点的所有子节点,以及直到树叶的子节点。由于树未展开,我无法使用下面的代码获取子级

onClick: function(item, node) {
            var childTreeNode = node.getChildren();
}
在这种情况下,如何获取子级和子级详细信息

下面的fiddle链接包含该树

HTML代码:

<div id="contentHere"></div>
<div id="contentButton">
    <button>Try it</button>
</div>  

试试看
JavaScript:

require([
    "dojo/_base/window", "dojo/store/Memory",
    "dijit/tree/ObjectStoreModel",
    "dijit/Tree", "dijit/form/CheckBox", "dojo/dom",
    "dojo/domReady!"], function (win, Memory, ObjectStoreModel, Tree, checkBox, dom) {

    // Create test store, adding the getChildren() method required by ObjectStoreModel
    var myStore = new Memory({
        data: [{
            id: 'world',
            name: 'The earth',
            type: 'planet',
            population: '6 billion'
        }, {
            id: 'AF',
            name: 'Africa',
            type: 'continent',
            population: '900 million',
            area: '30,221,532 sq km',
            timezone: '-1 UTC to +4 UTC',
            parent: 'world'
        }, {
            id: 'EG',
            name: 'Egypt',
            type: 'country',
            parent: 'AF'
        }, {
            id: 'KE',
            name: 'Kenya',
            type: 'country',
            parent: 'AF'
        }, {
            id: 'Nairobi',
            name: 'Nairobi',
            type: 'city',
            parent: 'KE'
        }, {
            id: 'Mombasa',
            name: 'Mombasa',
            type: 'city',
            parent: 'KE'
        }, {
            id: 'SD',
            name: 'Sudan',
            type: 'country',
            parent: 'AF'
        }, {
            id: 'Khartoum',
            name: 'Khartoum',
            type: 'city',
            parent: 'SD'
        }, {
            id: 'AS',
            name: 'Asia',
            type: 'continent',
            parent: 'world'
        }, {
            id: 'CN',
            name: 'China',
            type: 'country',
            parent: 'AS'
        }, {
            id: 'IN',
            name: 'India',
            type: 'country',
            parent: 'AS'
        }, {
            id: 'RU',
            name: 'Russia',
            type: 'country',
            parent: 'AS'
        }, {
            id: 'MN',
            name: 'Mongolia',
            type: 'country',
            parent: 'AS'
        }, {
            id: 'OC',
            name: 'Oceania',
            type: 'continent',
            population: '21 million',
            parent: 'world'
        }, {
            id: 'EU',
            name: 'Europe',
            type: 'continent',
            parent: 'world'
        }, {
            id: 'DE',
            name: 'Germany',
            type: 'country',
            parent: 'EU'
        }, {
            id: 'FR',
            name: 'France',
            type: 'country',
            parent: 'EU'
        }, {
            id: 'ES',
            name: 'Spain',
            type: 'country',
            parent: 'EU'
        }, {
            id: 'IT',
            name: 'Italy',
            type: 'country',
            parent: 'EU'
        }, {
            id: 'RU',
            name: 'Russia',
            type: 'country',
            parent: 'EU'
        }, {
            id: 'NA',
            name: 'North America',
            type: 'continent',
            parent: 'world'
        }, {
            id: 'SA',
            name: 'South America',
            type: 'continent',
            parent: 'world'
        }],
        getChildren: function (object) {
            return this.query({
                parent: object.id
            });
        }
    });

    // Create the model
    var myModel = new ObjectStoreModel({
        store: myStore,
        query: {
            id: 'world'
        }
    });

    // Create the Tree.
    var tree = new Tree({
        model: myModel,
        getIconClass: function (item, opened) {
            //   console.log('tree getIconClass', item, opened);
            //   console.log('tree item type', item.type);
        },


        onClick: function (item, node) {
            node._iconClass = "dijitFolderClosed";
            node.iconNode.className = "dijitFolderClosed";
            console.log(node.domNode.id);
            var id = node.domNode.id,
                isNodeSelected = node.checkBox.get('checked');
            console.log(isNodeSelected);
            checkTheChild(node, isNodeSelected);

            /*dojo.query('#'+id+' .dijitCheckBox').forEach(function(node){ 
                    console.log("node in checkbox :"+node);
                        dijit.getEnclosingWidget(node).set('checked',isNodeSelected);
                    });*/
        },
        _createTreeNode: function (args) {
            var tnode = new dijit._TreeNode(args);
            tnode.labelNode.innerHTML = args.label;
            console.log(args);
            var cb = new dijit.form.CheckBox();
            cb.placeAt(tnode.labelNode, "first");
            tnode.checkBox = cb;
            return tnode;
        }
    });
    tree.placeAt(contentHere);
    tree.startup();
    //tree.expandAll();
    var nodeMap = tree._itemNodesMap;

});

function retrievInfo() {

    dojo.query('.dijitChecked').forEach(function (node) {
        dojo.query('#nodeContent')[0].innerHTML += node.parentNode.parentNode.textContent;
        //dojo.query('#nodeContent')[0].innerHTML += node.label;
        var treeNode = dijit.getEnclosingWidget(this.domNode.parentNode);
        console.log(node.parentNode.parentNode.textContent);
        console.log(node.parentNode.parentNode.textContent);
        var nodeMap = tree._itemNodesMap;

    });
}

function checkTheChild(node1, isNodeSelected1) {
    console.log(node1);
    console.log(isNodeSelected1);
    var childTreeNode = node1.getChildren();
    var x;
    if (childTreeNode.length > 0) {
        //for(i=0;i<childTreeNode.length;i++){
        for (x in childTreeNode) {
            //childTreeNode[i].checkBox.checked = true;
            childTreeNode[x].checkBox.setAttribute('checked', isNodeSelected1);
            //dijit.getEnclosingWidget(node1.domNode).set('checked',isNodeSelected1);
            if (childTreeNode[x].getChildren().length > 0) {
                checkTheChild(childTreeNode[x], isNodeSelected1);
            }
        }

    } else {
        return;
    }
}
需要([
“dojo/_base/window”、“dojo/store/Memory”,
“dijit/tree/ObjectStoreModel”,
“dijit/Tree”、“dijit/form/CheckBox”、“dojo/dom”,
“dojo/domReady!”],函数(win、内存、ObjectStoreModel、树、复选框、dom){
//创建测试存储,添加ObjectStoreModel所需的getChildren()方法
var myStore=新内存({
数据:[{
id:“世界”,
名字:'地球',
类型:'行星',
人口:60亿
}, {
id:'AF',
名称:“非洲”,
类型:'大陆',
人口:9亿,
面积:30221532平方公里,
时区:'-1 UTC至+4 UTC',
家长:“世界”
}, {
id:'EG',
名称:“埃及”,
类型:'国家',
家长:“AF”
}, {
id:'可',
名称:'肯尼亚',
类型:'国家',
家长:“AF”
}, {
id:'内罗毕',
名称:“内罗毕”,
类型:'城市',
家长:“柯”
}, {
id:'蒙巴萨',
名称:“蒙巴萨”,
类型:'城市',
家长:“柯”
}, {
id:'SD',
名称:'苏丹',
类型:'国家',
家长:“AF”
}, {
id:'喀土穆',
名称:“喀土穆”,
类型:'城市',
家长:“SD”
}, {
id:'作为',
名称:"亚洲",,
类型:'大陆',
家长:“世界”
}, {
id:'CN',
名称:"中国",,
类型:'国家',
家长:“AS”
}, {
id:'在',
名称:"印度",,
类型:'国家',
家长:“AS”
}, {
id:'RU',
名称:"俄罗斯",,
类型:'国家',
家长:“AS”
}, {
id:'MN',
名称:"蒙古",,
类型:'国家',
家长:“AS”
}, {
id:'OC',
名称:“大洋洲”,
类型:'大陆',
人口:2100万,
家长:“世界”
}, {
id:'欧盟',
名称:"欧洲",,
类型:'大陆',
家长:“世界”
}, {
id:'DE',
名称:“德国”,
类型:'国家',
家长:“欧盟”
}, {
id:'FR',
名称:“法国”,
类型:'国家',
家长:“欧盟”
}, {
id:'ES',
名称:“西班牙”,
类型:'国家',
家长:“欧盟”
}, {
id:'它',
名称:“意大利”,
类型:'国家',
家长:“欧盟”
}, {
id:'RU',
名称:"俄罗斯",,
类型:'国家',
家长:“欧盟”
}, {
id:'不适用',
名称:“北美”,
类型:'大陆',
家长:“世界”
}, {
id:'SA',
名称:'南美洲',
类型:'大陆',
家长:“世界”
}],
getChildren:函数(对象){
返回此.query({
父对象:object.id
});
}
});
//创建模型
var myModel=新的ObjectStoreModel({
商店:myStore,
查询:{
id:“世界”
}
});
//创建树。
var-tree=新树({
型号:myModel,
getIconClass:函数(项,已打开){
//日志('tree getIconClass',项,已打开);
//console.log('tree item type',item.type);
},
onClick:函数(项、节点){
节点。_iconClass=“dijitFolderClosed”;
node.iconNode.className=“dijitFolderClosed”;
log(node.domNode.id);
var id=node.domNode.id,
isNodeSelected=node.checkBox.get('checked');
console.log(isNodeSelected);
选中Child(节点,isNodeSelected);
/*查询('#'+id+'.dijitCheckBox').forEach(函数(节点){
log(“复选框中的节点:“+node”);
dijit.getEnclosuringWidget(node.set('checked',isNodeSelected);
});*/
},
_createTreeNode:函数(args){
var tnode=新的dijit.\u TreeNode(args);
tnode.labelNode.innerHTML=args.label;
console.log(args);
var cb=new dijit.form.CheckBox();
cb.placeAt(tnode.labelNode,“第一”);
tnode.checkBox=cb;
返回tnode;
}
});
tree.placeAt(contentHere);
tree.startup();
//tree.expandAll();
var nodeMap=tree.\u itemnodemap;
});
函数retrievInfo(){
query('.dijitChecked').forEach(函数(节点){
查询('#nodeContent')[0].innerHTML+=node.parentNode.parentNode.textContent;
//query('#nodeContent')[0].innerHTML+=node.label;
var treeNode=dijit.getEnclosuringWidget(this.domNode.parentNode);
log(node.parentNode.parentNode.textContent);
log(node.parentNode.parentNode.textContent);
var nodeMap=tree.\u itemnodemap;
});
}
函数检查子节点(节点1,IsNodeSelected 1){
控制台日志(node1);
console.log(isNodeSelected1);
瓦尔·奇尔德