我想使用 ExtJS4 创建 TreePanel。所以我将 JSON 发送给具有以下格式的代理阅读器
{
"text": "en",
"children": {
"text": "/",
"children": [{
"text": "/page",
"children": [{
"text": "/page/new",
"children": [],
"leaf": true,
"expanded": false
},
{
"text": "/page/remove",
"children": [],
"leaf": true,
"expanded": false
}
],
"leaf": false,
"expanded": false
},
{
"text": "/home",
"children": [],
"leaf": true,
"expanded": false
}
],
"leaf": false,
"expanded": true
}
}
如果我希望 en
节点成为我的根节点,我该如何配置我的 Store。
Ext.define('Example.store.WebItems', {
extend: 'Ext.data.TreeStore',
model: 'Example.model.Item',
proxy: {
type: 'ajax',
api: {
read: 'some/url',
},
reader: {
type: 'json',
root: 'children' // Is this correct?
}
},
root: // What should I write here?
});
当我将 TreeStore
的根定义为 root: 'My Root'
时,它会添加新的根,但我想使用 JSON< 中定义的根
。
所以我的问题是:
- 如何使用 JSON 中的根节点而不是手动定义它?
- 是否还必须在代理读取器和 TreeStore 中定义根节点?
最佳答案
响应必须有 root
。
例如:
{
MyRoot: {
"text": "en",
"children": {
"text": "/",
"children": [{
"text": "/page",
"children": [{
"text": "/page/new",
"children": [],
"leaf": true,
"expanded": false
}, {
"text": "/page/remove",
"children": [],
"leaf": true,
"expanded": false
}],
"leaf": false,
"expanded": false
}, {
"text": "/home",
"children": [],
"leaf": true,
"expanded": false
}],
"leaf": false,
"expanded": true
}
}
}
在这个例子中,root
是 MyRoot
。现在你必须“告诉”读者你的 root
是 MyRoot
:
// ...
reader: {
type: 'json',
root: 'MyRoot'
}
},
//root: this config is not needed now
});
关于json - ExtJS4 如何从 JSON 设置 TreePanels 根节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6957485/