1

当我使用 时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'](不幸的是,它不起作用......)?

4

2 回答 2

0

我对 Json 文件和普通的延迟加载树也有同样的问题。

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

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

问候,

亚历克斯

于 2016-04-07T12:48:29.000 回答
0

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

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

这对我来说很好。

于 2016-04-05T14:42:06.287 回答