我的带有 treestore 的树最初被加载,但请求子节点失败。
在请求子节点时,localpath
会传输一个参数,该参数定义子节点数据所在的路径。
初始化请求:localpath=/
-> 获取所有子节点/
儿童请求:localpath=/subfolder1
-> 让所有儿童加入/subfolder1
我附上了两个屏幕截图,显示了初始加载和单击文件夹的时间。
顺便说一句:我树上的箭头去哪儿了?
Json:我的树商店接收这样的 json 数据:
{
"value": {
"name": "",
"path": "/",
"leaf": false,
"type": "folder",
"children": [
{
"name": "subfolder1",
"path": "/subfolder1",
"leaf": false,
"type": "folder",
"children": []
},
{
"name": "subfolder2",
"path": "/subfolder2",
"leaf": false,
"type": "folder",
"children": []
},
{
"name": "testreports",
"path": "/testreports",
"leaf": false,
"type": "folder",
"children": []
}
]
}
}
商店:树商店看起来像这样:
var oTreeStore = Ext.create( 'X.module.store.store.Tree', {
model : 'X.module.store.model.TreeNode',
api : this.httpApi,
module : "store",
func : "getchildren",
scope : "user"
} );
TreePanel创建:
var oTreePanel = Ext.create( 'X.module.store.view.TreePanel', {
store : oTreeStore
} );
树形面板定义:
constructor: function( oConfig ) {
var self = this;
//creating a proxy, which can communicate with HTTP-API
//and is able to parse it's json-tree format
var oProxy = Ext.create( 'X.lib.httpapiclient.Proxy', {
api : oConfig.api,
module : oConfig.module,
func : oConfig.func,
params : {
scope : oConfig.scope
},
reader : {
type: 'json',
root: function( o ) { return o.value? o.value.children : o.children; }
},
delay : oConfig.delay || 100,
success : oConfig.success || function() {},
progress: oConfig.progress || function() {},
error : oConfig.error || function() {}
} );
oConfig.nodeParam = 'localpath';
oConfig.proxy = oProxy;
self.callParent( arguments );
//the HTTP-API requires the ID of the root-node to be empty
self.on( 'beforeload', function( s, o ) {
if( o.params.localpath === 'root' ) o.params.localpath = '/';
} );
}
型号:型号...
Ext.define( 'X.module.store.model.TreeNode', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
{ name: 'path', type: 'string' },
{ name: 'type', type: 'string' }
]
} );