extjs4树存储加载远程数据并在本地使用它
我将我的树存储定义为:extjs4树存储加载远程数据并在本地使用它,extjs,extjs4,Extjs,Extjs4,我将我的树存储定义为: Ext.define('Portal.store.GroupsTreeStore', { extend: 'Ext.data.TreeStore', model: 'Portal.model.GroupTreeModel', autoLoad: false, proxy: { method: 'get', type: 'ajax', url: 'groups/get', r
Ext.define('Portal.store.GroupsTreeStore', {
extend: 'Ext.data.TreeStore',
model: 'Portal.model.GroupTreeModel',
autoLoad: false,
proxy: {
method: 'get',
type: 'ajax',
url: 'groups/get',
reader: {
type: 'json',
successProperty: 'success',
messageProperty: 'message',
root: 'data'
}
},
// Prevent auto loading
root: {
expanded: true,
text: "",
"data": []
}
});
我的模型是:
Ext.define('Portal.model.GroupTreeModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'type', type: 'string'}
]
});
我收到的JSON数据如下:
{
"success": true,
"message": "ok",
"data": [{
"name": "group1",
"type": "group",
"expanded": true,
"children": [{
"name": "admin_2503",
"type": "people",
"leaf": true
},
{
"name": "u1",
"type": "people",
"leaf": true
},
{
"name": "u2",
"type": "people",
"leaf": true
}]
},
{
"name": "group2",
"type": "group",
"expanded": false,
"leaf": false,
"children": [{
"name": "u5",
"type": "people",
"leaf": true
}]
}]
}
我想一次加载所有树存储数据,并在本地使用后加载(例如搜索、筛选等),但使用此存储配置,所有节点都显示未展开,并在展开操作时执行查询,以提供url:groups\get
和节点id,接收相同的JSON并添加group1
和group2
,作为节点子节点。为此,我应该如何配置我的存储
更新视图定义:
Ext.define('Portal.view.GroupsTree', {
extend: 'Ext.tree.Panel',
store: 'GroupsTreeStore',
border: false,
emptyText: 'No records found',
multiSelect: false,
rootVisible: false,
columns: [
{
xtype: 'treecolumn',
dataIndex: 'name',
flex: 1,
sortable: true,
text: 'Name'
}
],
initComponent: function () {
this.callParent(arguments);
}
})) 请查看此链接的答案,它可能导致您的体验 视图的定义?@yellen我更新了我的帖子。谢谢!它解决了我的问题!奇怪的行为:我一直认为
代理读取器root
属性指定了一个数据容器,而和数据的格式无关。