我想使用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
节点作为我的根节点,我如何配置我的商店。
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
中定义的根。
所以我的问题是:
答案 0 :(得分:5)
响应必须为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
});
答案 1 :(得分:1)
据我所知,你需要指定root如下:
root: {
text: 'en',
id: 'src',
expanded: true '
}
尝试上面的代码段,它会对你有帮助。
答案 2 :(得分:0)
可能会迟到但是对于其他人来说,将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
}
}]
删除阅读器块
reader: {
type: 'json',
root: 'MyRoot'
}
添加根块:</ p>
root: {
text: 'en',
id: 'src',
expanded: true '
}
在rootVisible: false
中添加treepanel
。