我们如何在 dojo TreeGrid 中设置 children?

How can we set children in dojo TreeGrid?

我在使用LazyTreeGrid的时候遇到了一个小问题; 我有这样的文件 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'}
   ]     
 }
}

我不知道如何在 ForestStoreModel 中设置 children,也许像 childrenAttrs:['description.compents'](不幸的是,它不起作用...)?

我找到了一个解决方案,我们可以这样使用onComplete

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

这对我来说很好。

我在 Json 文件和正常的延迟加载树中遇到了同样的问题。

为了得到children,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});
            }
        });

我不知道您是否必须从另一台服务器获取您的 json 文件,但也许它会以类似的方式工作!

你好,

亚历克斯