当我使用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']
(不幸的是,它不起作用......)?
答案 0 :(得分:0)
我找到了一个解决方案,我们可以像这样使用onComplete
var model = new ForestStoreModel( {
getChildren : function ( item, onComplete, onError ) {
onComplete( item.dataDescription.components );
}
} );
这对我来说很好。
答案 1 :(得分:0)
我对Json文件和普通的延迟加载树也有同样的问题。
为了得到孩子,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文件,但它可能会有类似的效果!
问候,
亚历