gpt4 book ai didi

json - Extjs 树面板 store.load() 问题

转载 作者:行者123 更新时间:2023-12-05 04:16:46 25 4
gpt4 key购买 nike

我发现很多树的例子是通过静态存储中的根数据加载的,或者是通过加载数据 TreeView 的树存储加载的,最终提前加载树。

我的要求是树最初是空的,没有数据,所以我在树存储上使用 removeAll 来实现它,即使最初加载了 tee。

我正在使用 ExtJs V 5.0.1。

接下来点击按钮,我通过 store.load 方法加载树。

保存在php rest服务输出的json文件中的树数据。

单击按钮后树加载正常。 问题是所有折叠或展开事件都只能起作用。在我的例子中,第一个元素展开后将折叠一次,然后不会展开。同样对于折叠的子元素,一旦展开就不会折叠。

在下面添加我的代码

Ext.define('TestTheme2.controller.Controller', {
extend: 'Ext.app.Controller',

requires: [
'Ext.window.MessageBox'
],

stores: [

],

config: {
isGridInspected: false
},

refs: {
treeGrid: '#treegrid'
},

control: {

"#treegrid":{
afterrender: 'afterViewRender'
},
"#loadButton":{

click:'onBtnClick'
}


},

afterViewRender: function(component, eOpts){
this.getTreeGrid().getStore().removeAll();
},

onBtnClick: function(){
this.getTreeGrid().getStore().load();
}

});

我的查看代码

Ext.define('TestTheme2.view.MyTreeGrid', {
extend: 'Ext.tree.Panel',
alias: 'widget.MyTreeGrid',


requires: [
'TestTheme2.store.MyStore',
'Ext.tree.View',
'Ext.grid.column.Check',
'Ext.tree.Column',
'Ext.grid.column.Widget',
'Ext.button.Button',
'Ext.menu.Menu',
'Ext.menu.Item',
'Ext.data.*',
'Ext.grid.*',
'Ext.tree.*',
],


itemId: 'treegrid',
width: '',
title: '',
allowDeselect: true,
enableColumnHide: false,
rowLines: true,
scroll: 'vertical',
sortableColumns: false,
store: 'MyStore',
rootVisible: false,

viewConfig: {
itemId: 'mytreeview2',
enableTextSelection: false,
markDirty: false,
stripeRows: true,
animate: true
},
columns: [
{
xtype: 'checkcolumn',
itemId: 'mycheck',
width: 50,
sortable: false,
dataIndex: 'mark',
text: ''
},
{
xtype: 'treecolumn',
width: 120,
sortable: false,
dataIndex: 'year',
text: 'Year',
flex: 1
},
{
xtype: 'gridcolumn',
width: 120,
sortable: false,
dataIndex: 'week',
text: 'Week'
},
{
xtype: 'gridcolumn',
width: 110,
sortable: false,
dataIndex: 'startdate',
text: 'Start Date'
},
{
xtype: 'gridcolumn',
width: 110,
sortable: false,
dataIndex: 'enddate',
text: 'End Date'
}
]

});

我的商店代码

Ext.define('TestTheme2.store.MyStore', {
extend: 'Ext.data.TreeStore',

requires: [
'TestTheme2.model.MyModel'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyStore',
model: 'TestTheme2.model.MyModel',
proxy: {
type: 'ajax',
url: '../../PhpWS/MockRestFlow?Service=MyService&type=byweek'
}
}, cfg)]);
}

});

我的模型代码

Ext.define('TestTheme2.model.MyModel', {
extend: 'Ext.data.Model',

requires: [
'Ext.data.field.Field'
],

fields: [
{
name: 'year'
},
{
name: 'week'
}
{
name: 'startdate'
},
{
name: 'enddate'
}
{
name: 'mark'
}

]

});

我的 Json 文件

{
text: '.',
children: [
{
year: 2014,
week: 33,
synergyid: '',
startdate: '01/11/2014',
enddate: '02/11/2014',
mark: false,
expanded: true,
children: [
{
year: 2014,
week: 33,
startdate: '03/11/2014',
enddate: '04/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 33,
startdate: '05/11/2014',
enddate: '06/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 33,
startdate: '07/11/2014',
enddate: '08/11/2014',
mark: false,
leaf: true
}
]
},
{
year: 2014,
week: 34,
startdate: '09/11/2014',
enddate: '10/11/2014',
expanded: false,
mark: false,
children: [
{
year: '2014',
week: 34,
startdate: '11/11/2014',
enddate: '12/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 34,
startdate: '13/11/2014',
enddate: '14/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 34,
startdate: '15/11/2014',
enddate: '16/11/2014',
mark: false,
leaf: true
}
]
},
{
year: 2014,
week: 35,
startdate: '17/11/2014',
enddate: '18/11/2014',
mark: false,
expanded: false,
children: [
{
year: 2014,
week: 35,
startdate: '19/11/2014',
enddate: '20/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 35,
startdate: '21/11/2014',
enddate: '22/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 35,
startdate: '23/11/2014',
enddate: '24/11/2014',
mark: false,
leaf: true
}
]
},
{
year: 2014,
week: 36,
startdate: '17/11/2014',
enddate: '18/11/2014',
mark: false,
expanded: false,
children: [
{
year: 2014,
week: 36,
startdate: '19/11/2014',
enddate: '20/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 36,
startdate: '21/11/2014',
enddate: '22/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 36,
startdate: '23/11/2014',
enddate: '24/11/2014',
mark: false,
leaf: true
}
]
},
{
year: 2014,
week: 37,
startdate: '17/11/2014',
enddate: '18/11/2014',
mark: false,
expanded: false,
children: [
{
year: 2014,
week: 37,
startdate: '19/11/2014',
enddate: '20/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 37,
startdate: '21/11/2014',
enddate: '22/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 37,
startdate: '23/11/2014',
enddate: '24/11/2014',
mark: false,
leaf: true
}
]
},
{
year: 2014,
week: 37,
startdate: '17/11/2014',
enddate: '18/11/2014',
mark: false,
expanded: false,
children: [
{
year: 2014,
week: 37,
startdate: '19/11/2014',
enddate: '20/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 37,
startdate: '21/11/2014',
enddate: '22/11/2014',
mark: false,
leaf: true
},
{
year: 2014,
week: 37,
startdate: '23/11/2014',
enddate: '24/11/2014',
mark: false,
leaf: true
}
]
}
]
}

最佳答案

与其在渲染后删除存储值并在单击按钮时再次加载存储,不如试试下面我在帖子中看到的方法,

只需定义一个最初没有子项的空扩展根,然后您可以随时加载商店:

 Ext.create('Ext.data.TreeStore', {
model: '...',
proxy: {
type: 'ajax',
reader: {
type: 'json',
root: 'data'
},
api: {
read : 'some url'
}
folderSort: true,
rootVisible: false,
root: {expanded: true, text: "", "data": []} // <- Inline root
});

在显式 .load 之后,内联根被覆盖。 希望对您有所帮助。

关于json - Extjs 树面板 store.load() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26353163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com