简体   繁体   English

我们如何在dojo TreeGrid中设置子项?

[英]How can we set children in dojo TreeGrid?

when I use the LazyTreeGrid , I met a little problem; 当我使用LazyTreeGrid ,我遇到了一个小问题; I have the file JSON like this: 我有这样的文件JSON:

{id: 'AF', name:'Africa',description:""},
{id: 'EG', name:'Egypt',description:""},
{id: 'KE', name:'Kenya',description:
 {
  compents: 
   [
    {id: 'Nairobi', name:'Nairobi', type:'city'},
    {id: 'Mombasa', name:'Mombasa', type:'city'}
   ]     
 }
}

I have no idea about how to set children in ForestStoreModel , maybe like childrenAttrs:['description.compents'] (unfortunately, it doesn't work...)? 我不知道如何在ForestStoreModel设置子ForestStoreModel ,也许像childrenAttrs:['description.compents'] (不幸的是,它不起作用......)?

I found one solution, we can use onComplete like this 我找到了一个解决方案,我们可以像这样使用onComplete

var model = new ForestStoreModel( {
    getChildren : function ( item, onComplete, onError ) {
        onComplete( item.dataDescription.components );
        }
} );

That works fine for me. 这对我来说很好。

I had the same same problem with a Json File and a normal lazyloading Tree. 我对Json文件和普通的延迟加载树也有同样的问题。

To get the children, id did it like this 为了得到孩子,id就是这样做的

var restStore = new JsonRest
    ({
        target: "http://localhost........",
        headers: { 'Content-Type': 'application/json;charset=utf-8' }
    });

    // Get an object by identity, then the remaining code will be executed (because of the async)
    // Otherwise the remaining code will be executed, before we get the object from the server (it wouldn't work)
    restStore.get("").then(function(items)
    {
        // set up a local store to get the tree data, plus define the method
        // to query the children of a node
        var MemoryStore = new Memory
        ({
            data: items,
            getChildren: function(object)
            {
                return this.query({parent: object.id});
            }
        });

I dont know if you have to get your json file from another server, but maybe it will work similar! 我不知道你是否必须从另一台服务器获取你的json文件,但也许它会起作用!

Greetings, 问候,

Alex 亚历克斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM