Javascript 我们如何在dojo TreeGrid中设置孩子?
当我使用Javascript 我们如何在dojo TreeGrid中设置孩子?,javascript,dojo,dojox.grid.datagrid,dojox.grid,dojo.gridx,Javascript,Dojo,Dojox.grid.datagrid,Dojox.grid,Dojo.gridx,当我使用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: 'Mombas
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 );
}
} );
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});
}
});
这对我来说很好。我找到了一个解决方案,我们可以像这样使用
onComplete
var model = new ForestStoreModel( {
getChildren : function ( item, onComplete, onError ) {
onComplete( item.dataDescription.components );
}
} );
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文件和正常的懒散加载树,我也有同样的问题 为了得到孩子们,我这样做了
var model = new ForestStoreModel( {
getChildren : function ( item, onComplete, onError ) {
onComplete( item.dataDescription.components );
}
} );
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我对Json文件和正常的lazyloading树也有同样的问题 为了得到孩子们,我这样做了
var model = new ForestStoreModel( {
getChildren : function ( item, onComplete, onError ) {
onComplete( item.dataDescription.components );
}
} );
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谢谢Alex,问题是孩子们不在以下级别(在
description.compents
中)。所以我使用onComplete(item.dataDescription.components)解决了这个问题代码>:)谢谢Alex,问题是孩子们不在以下级别(在description.compents
中)。所以我使用onComplete(item.dataDescription.components)解决了这个问题代码>:)