我们如何在dojo树网格中设置孩子

How can we set children in dojo TreeGrid?

本文关键字:网格 设置 孩子 树网 dojo 我们      更新时间:2023-12-08

当我使用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中设置子项,也许像childrenAttrs:['description.compents']一样(不幸的是,它不起作用…)?

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

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

这对我来说很好。

我在Json文件和普通lazyloading树上也遇到了同样的问题。

为了得到孩子们,我像这样做了

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文件,但也许它也能类似地工作!

问候,

Alex