Extjs4---Cannot read property 'addCls' of null
2013-03-28 07:15
309 查看
做后台管理系统时遇到的问题,关于tab关闭后再打开不显示,或者报错
我在新的tabpanel中加入了一个grid,当我关闭再次打开就会报错Cannot read property 'addCls' of null,
原因是我在定义grid的错误
这是错误代码:
[javascript] view
plaincopy
Ext.define('HT.view.Grid',{
extend:'Ext.grid.Panel',
title : '人员列表',
width:400,
height:170,
frame:true,
store: {
fields: ['id','name','sex','age','birthday'],
proxy: {
type: 'ajax',
url : 'users',
reader: {
type: 'json',//Ext.data.reader.Json解析器
root: 'users'
}
},
autoLoad: true
},
columns: [//配置表格列
new Ext.grid.RowNumberer(),//表格行号组件
{header: "编号", width: 80, dataIndex: 'id', sortable: true},
{header: "姓名", width: 80, dataIndex: 'name', sortable: true},
{header: "年龄", width: 80, dataIndex: 'age', sortable: true},
{header: "性别", width: 80, dataIndex: 'sex', sortable: true},
{header: "生日", width: 80, dataIndex: 'birthdate', sortable: true}
]
});
应该改为这个:
[javascript] view
plaincopy
Ext.define('HT.view.Grid',{
extend:'Ext.grid.Panel',
title : '人员列表',
initComponent:function(){
Ext.apply(this,{
width:400,
height:170,
frame:true,
store: {
fields: ['id','name','sex','age','birthday'],
proxy: {
type: 'ajax',
url : 'users',
reader: {
type: 'json',//Ext.data.reader.Json解析器
root: 'users'
}
},
autoLoad: true
},
columns: [//配置表格列
new Ext.grid.RowNumberer(),//表格行号组件
{header: "编号", width: 80, dataIndex: 'id', sortable: true},
{header: "姓名", width: 80, dataIndex: 'name', sortable: true},
{header: "年龄", width: 80, dataIndex: 'age', sortable: true},
{header: "性别", width: 80, dataIndex: 'sex', sortable: true},
{header: "生日", width: 80, dataIndex: 'birthdate', sortable: true}
]
}),
this.callParent(arguments);
}
});
看样子属性的设置都要用apply方法设置进去
http://www.jishu521.com/post/menogxinjinglong/8110408.html
=================================================================================================
之前的理解肤浅
Cannot read property 'addCls' of null
一般出现在这种场景下
create a window ,window的 Ext.define 时的 items 你写的是 Ext.create出来的某个组件,而不是{xtype:'xxx'}这种形式
当window关闭时,它会把把自己内部包含的组件也destroy掉,这样你第二次 create 这个window的时候 内部 引用的那个组件已经被销毁了,就错误产生了。
但是你如果是{xtype:'xxx'}这种形式的话 那么 每一次 create 都会重新创建内部组件。
所以 建议是 内部 items 里 保持{xtype:'xxx'}形式定义子组件
我在新的tabpanel中加入了一个grid,当我关闭再次打开就会报错Cannot read property 'addCls' of null,
原因是我在定义grid的错误
这是错误代码:
[javascript] view
plaincopy
Ext.define('HT.view.Grid',{
extend:'Ext.grid.Panel',
title : '人员列表',
width:400,
height:170,
frame:true,
store: {
fields: ['id','name','sex','age','birthday'],
proxy: {
type: 'ajax',
url : 'users',
reader: {
type: 'json',//Ext.data.reader.Json解析器
root: 'users'
}
},
autoLoad: true
},
columns: [//配置表格列
new Ext.grid.RowNumberer(),//表格行号组件
{header: "编号", width: 80, dataIndex: 'id', sortable: true},
{header: "姓名", width: 80, dataIndex: 'name', sortable: true},
{header: "年龄", width: 80, dataIndex: 'age', sortable: true},
{header: "性别", width: 80, dataIndex: 'sex', sortable: true},
{header: "生日", width: 80, dataIndex: 'birthdate', sortable: true}
]
});
应该改为这个:
[javascript] view
plaincopy
Ext.define('HT.view.Grid',{
extend:'Ext.grid.Panel',
title : '人员列表',
initComponent:function(){
Ext.apply(this,{
width:400,
height:170,
frame:true,
store: {
fields: ['id','name','sex','age','birthday'],
proxy: {
type: 'ajax',
url : 'users',
reader: {
type: 'json',//Ext.data.reader.Json解析器
root: 'users'
}
},
autoLoad: true
},
columns: [//配置表格列
new Ext.grid.RowNumberer(),//表格行号组件
{header: "编号", width: 80, dataIndex: 'id', sortable: true},
{header: "姓名", width: 80, dataIndex: 'name', sortable: true},
{header: "年龄", width: 80, dataIndex: 'age', sortable: true},
{header: "性别", width: 80, dataIndex: 'sex', sortable: true},
{header: "生日", width: 80, dataIndex: 'birthdate', sortable: true}
]
}),
this.callParent(arguments);
}
});
看样子属性的设置都要用apply方法设置进去
http://www.jishu521.com/post/menogxinjinglong/8110408.html
=================================================================================================
之前的理解肤浅
Cannot read property 'addCls' of null
一般出现在这种场景下
create a window ,window的 Ext.define 时的 items 你写的是 Ext.create出来的某个组件,而不是{xtype:'xxx'}这种形式
当window关闭时,它会把把自己内部包含的组件也destroy掉,这样你第二次 create 这个window的时候 内部 引用的那个组件已经被销毁了,就错误产生了。
但是你如果是{xtype:'xxx'}这种形式的话 那么 每一次 create 都会重新创建内部组件。
所以 建议是 内部 items 里 保持{xtype:'xxx'}形式定义子组件
相关文章推荐
- NHibernate3.3.0GA+ExtJS4.1.1+ASP.NET MVC3.0权限管理系统(4)--关于(3)报错"Cannot read property 'addCls' of null"
- Extjs4---Cannot read property 'addCls' of null
- Extjs4---Cannot read property 'addCls' of null
- Extjs4---Cannot read property 'addCls' of null
- 【ExtJS】Uncaught TypeError: Cannot read property 'length' of null
- 【ExtJS】Cannot call method 'removeCls'或'addCls' of null
- canvas 在chrome预览时 Cannot read property 'getContext' of null
- TypeError: Cannot read property 'style' of null 错误解决
- openlayers Uncaught TypeError: Cannot read property 'wrapDateLine' of null
- 【cocos2d-js系列问题】Cannot read property 'x' of null错误解决办法
- echarts-all.js:1 Uncaught TypeError: Cannot read property 'getAttribute' of null
- Uncaught TypeError: Cannot read property 'length' of null
- datagrid报Cannot read property '' of null
- Uncaught TypeError: Cannot read property 'length' of null
- Cannot read property 'root' of null 解决方法
- TypeError: Cannot read property 'style' of null 错误解决
- 关于JS出现的Cannot read property 'XXX' of null错误
- Uncaught TypeError: Cannot read property 'drawImage' of undefined错误的解决办法
- ExtJS错误解决 Cannot read property 'on' of undefined
- Ckeditor: Uncaught TypeError: Cannot read property 'keyCode' of undefined 解决方法