0
我的樹與treestore最初被加載,但請求的子節點失敗。ExtJs - 如何使用動態參數加載TreeStore
在請求孩子時,傳輸參數localpath
,該參數定義了子數據所在的路徑。
初始化請求:localpath=/
- >得到所有的孩子在/
兒童要求:localpath=/subfolder1
- >得到所有的孩子在/subfolder1
我附上兩張截圖顯示初始加載和顯示文件夾時,點擊。
BTW:哪裏有箭頭我的樹不見了?
的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
});
TreePanel中定義:
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' }
]
});