Extjs6问题——grid不显示数据
2016-04-06 19:14
393 查看
使用MVVC框架显示一个表格,遇到gridPanel只显示表头,但是不显示数据的问题,可以从以下的几个角度考虑。
1. 数据是否有问题?检查返回的json数据结构是否与reader对应。
2. models里面fields对应关系是否正确?保险起见最好加上mapping。
3. 比较诡异的一个问题是define view的时候,store如果是引用的方式,即:store:’{xxx}‘,store并不会在view 被创建的时候创建一个实例,这里强制在store的时候用store:Ext.create('xxx.xx.xxx');才正确的加载了数据。
下面记录下更正之后的代码:
View:
Ext.define('Admin.view.dashboard.MalfunctionListInbox',{
extend: 'Ext.grid.GridPanel',
xtype: 'malfunctionlistinbox',
alias: 'widget.malfunctionlistinbox',
requires: [
'Ext.grid.GridPanel',
'Ext.grid.View',
'Ext.selection.CheckboxModel',
'Admin.view.dashboard.MalfunctionListInboxController',
'Admin.view.dashboard.MalfunctionListModel',
'Admin.store.dashboard.MalfunctionListStore'
],
cls: 'email-inbox-panel shadow-panel',
viewModel:{
type: 'malfunctionlist'
},
store:Ext.create('Admin.store.dashboard.MalfunctionListStore'),
controller: 'malfunctionlistcontroller',
ViewConfig:{
preserveScrollOnRefresh: true,
preserveScrollOnReload: true,
},
selModel: {
selType: 'checkboxmodel',
checkOnly: true,
showHeaderCheckbox: true
},
listeners: {
'cellclick': 'onGridCellItemClick'
},
layout:{
type : 'fit',
},
headerBorders: false,
rowLines: false,
autoRender:true,
columns:[
{
xtype:'gridcolumn',
dataIndex:'id',
text:'id',
hidden:true
},
{
xtype:'gridcolumn',
dataIndex: 'date',
text:'日期',
width:90,
renderer:Ext.util.Format.dateRenderer('Y年m月d日 H:i')
},
{
xtype:'gridcolumn',
dataIndex:'unit_name',
text:'单位名称'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_name',
text:'故障名称'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_type',
text:'故障线路类型'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_nature',
text:'故障性质'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_reason',
text:'故障原因'
}
]
});
ViewModel:
Ext.define('Admin.view.dashboard.MalfunctionListModel',{
extend:'Ext.app.ViewModel',
requires:[
'Admin.store.dashboard.MalfunctionListStore',
'Admin.model.dashboard.MalfunctionListModel'
],
alias:'viewmodel.malfunctionlist',
stores:{
MalfunctionList: {
xtype: 'MalfunctionListStore'
}
}
});
Store:
Ext.define("Admin.store.dashboard.MalfunctionListStore",{
extend: 'Ext.data.Store',
alias:'store.MalfunctionListStore',
requires:[
'Admin.model.dashboard.MalfunctionListModel',
'Ext.window.MessageBox'
],
id: 'malfunctionlist',
model:'Admin.model.dashboard.MalfunctionListModel',
//pageSize:20,
autoLoad:true,
proxy:{
type:'ajax',
url: '/app/data/dashboard/MalfunctionList.json',
reader: {
type:'json',
rootProperty:'data',
successProperty:'success',
actionMethods:{
read: 'GET'
}
}
}
});
Model:
Ext.define("Admin.model.dashboard.MalfunctionListModel",{
extend: 'Admin.model.Base',
idProperty: 'id',
field:[
{
type: 'int',
name: 'id',
mapping:'id'
},
{
type:'date',
name:'date',
dateFormat:'Y-m-dTH:i',
mapping: 'date'
},
{
type:'string',
name:'unit_name',
mapping: 'unit_name'
},
{
type:'string',
name:'malfunction_name',
mapping:'malfunction_name'
},
{
type:'string',
name:'malfunction_type',
mapping:'malfunction_type'
},
{
type:'string',
name:'malfunction_nature',
mapping:'malfunction_nature'
},
{
type:'string',
name:'malfunction_reason',
mapping:'malfunction_reason'
}
]
});
1. 数据是否有问题?检查返回的json数据结构是否与reader对应。
2. models里面fields对应关系是否正确?保险起见最好加上mapping。
3. 比较诡异的一个问题是define view的时候,store如果是引用的方式,即:store:’{xxx}‘,store并不会在view 被创建的时候创建一个实例,这里强制在store的时候用store:Ext.create('xxx.xx.xxx');才正确的加载了数据。
下面记录下更正之后的代码:
View:
Ext.define('Admin.view.dashboard.MalfunctionListInbox',{
extend: 'Ext.grid.GridPanel',
xtype: 'malfunctionlistinbox',
alias: 'widget.malfunctionlistinbox',
requires: [
'Ext.grid.GridPanel',
'Ext.grid.View',
'Ext.selection.CheckboxModel',
'Admin.view.dashboard.MalfunctionListInboxController',
'Admin.view.dashboard.MalfunctionListModel',
'Admin.store.dashboard.MalfunctionListStore'
],
cls: 'email-inbox-panel shadow-panel',
viewModel:{
type: 'malfunctionlist'
},
store:Ext.create('Admin.store.dashboard.MalfunctionListStore'),
controller: 'malfunctionlistcontroller',
ViewConfig:{
preserveScrollOnRefresh: true,
preserveScrollOnReload: true,
},
selModel: {
selType: 'checkboxmodel',
checkOnly: true,
showHeaderCheckbox: true
},
listeners: {
'cellclick': 'onGridCellItemClick'
},
layout:{
type : 'fit',
},
headerBorders: false,
rowLines: false,
autoRender:true,
columns:[
{
xtype:'gridcolumn',
dataIndex:'id',
text:'id',
hidden:true
},
{
xtype:'gridcolumn',
dataIndex: 'date',
text:'日期',
width:90,
renderer:Ext.util.Format.dateRenderer('Y年m月d日 H:i')
},
{
xtype:'gridcolumn',
dataIndex:'unit_name',
text:'单位名称'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_name',
text:'故障名称'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_type',
text:'故障线路类型'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_nature',
text:'故障性质'
},
{
xtype:'gridcolumn',
dataIndex:'malfunction_reason',
text:'故障原因'
}
]
});
ViewModel:
Ext.define('Admin.view.dashboard.MalfunctionListModel',{
extend:'Ext.app.ViewModel',
requires:[
'Admin.store.dashboard.MalfunctionListStore',
'Admin.model.dashboard.MalfunctionListModel'
],
alias:'viewmodel.malfunctionlist',
stores:{
MalfunctionList: {
xtype: 'MalfunctionListStore'
}
}
});
Store:
Ext.define("Admin.store.dashboard.MalfunctionListStore",{
extend: 'Ext.data.Store',
alias:'store.MalfunctionListStore',
requires:[
'Admin.model.dashboard.MalfunctionListModel',
'Ext.window.MessageBox'
],
id: 'malfunctionlist',
model:'Admin.model.dashboard.MalfunctionListModel',
//pageSize:20,
autoLoad:true,
proxy:{
type:'ajax',
url: '/app/data/dashboard/MalfunctionList.json',
reader: {
type:'json',
rootProperty:'data',
successProperty:'success',
actionMethods:{
read: 'GET'
}
}
}
});
Model:
Ext.define("Admin.model.dashboard.MalfunctionListModel",{
extend: 'Admin.model.Base',
idProperty: 'id',
field:[
{
type: 'int',
name: 'id',
mapping:'id'
},
{
type:'date',
name:'date',
dateFormat:'Y-m-dTH:i',
mapping: 'date'
},
{
type:'string',
name:'unit_name',
mapping: 'unit_name'
},
{
type:'string',
name:'malfunction_name',
mapping:'malfunction_name'
},
{
type:'string',
name:'malfunction_type',
mapping:'malfunction_type'
},
{
type:'string',
name:'malfunction_nature',
mapping:'malfunction_nature'
},
{
type:'string',
name:'malfunction_reason',
mapping:'malfunction_reason'
}
]
});
相关文章推荐
- extjs grid取到数据而不显示的解决
- ExtJS下grid的一些属性说明
- Extjs在exlipse中设置自动提示的方法
- 常用Extjs工具:Extjs.util.Format使用方法
- extjs DataReader、JsonReader、XmlReader的构造方法
- 学习ExtJS(一) 之基础前提
- extjs 为某个事件设置拦截器
- ExtJs 学习笔记基础篇 Ext组件的使用第1/2页
- Extjs列表详细信息窗口新建后自动加载解决方法
- Extjs grid添加一个图片状态或者按钮的方法
- Extjs学习笔记之四 工具栏和菜单
- extjs form textfield的隐藏方法
- ExtJS 2.0实用简明教程之应用ExtJS
- ExtJS Store的数据访问与更新问题
- 不用写JS也能使用EXTJS视频演示
- Extjs改变树节点的勾选状态点击按钮将复选框去掉
- extjs 列表框(multiselect)的动态添加列表项的方法
- ExtJs默认的字体大小改变的几种方法(自己整理)
- ExtJS 配置和表格控件使用第1/2页
- 解决extjs在firefox中关闭窗口再打开后iframe中js函数访问不到的问题