做后台管理系统时遇到的问题,关于tab关闭后再打开不显示,或者报错
我在新的tabpanel中加入了一个grid,当我关闭再次打开就会报错Cannot read property 'addCls' of null,
原因是我在定义grid的错误
这是错误代码:
- 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}
- ]
- });
应该改为这个:
- 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'}形式定义子组件
-
顶
- 0
-
踩
- 0
-
猜你在找
id="iframeu1607657_0" src="http://pos.baidu.com/vclm?sz=728x90&rdid=1607657&dc=2&di=u1607657&dri=0&dis=0&dai=2&ps=3378x405&coa=at%3D3%26rsi0%3D728%26rsi1%3D90%26pat%3D6%26tn%3DbaiduCustNativeAD%26rss1%3D%2523FFFFFF%26conBW%3D1%26adp%3D1%26ptt%3D0%26titFF%3D%2525E5%2525BE%2525AE%2525E8%2525BD%2525AF%2525E9%25259B%252585%2525E9%2525BB%252591%26titFS%3D%26rss2%3D%2523000000%26titSU%3D0%26ptbg%3D90%26piw%3D0%26pih%3D0%26ptp%3D0&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1463714510730&ti=Extjs4---Cannot%20read%20property%20%27addCls%27%20of%20null%20-%20%E5%AD%99%E5%81%A5%E7%9A%84%E4%B8%93%E6%A0%8F%20-%20%E5%8D%9A%E5%AE%A2%E9%A2%91&ari=1&dbv=2&drs=3&pcs=1349x643&pss=1349x4199&cfv=0&cpl=4&chi=1&cce=true&cec=UTF-8&tlm=1463714510<u=http%3A%2F%2Fblog.youkuaiyun.com%2Fsuncaishen%2Farticle%2Fdetails%2F8731672<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DN6lrtUbWyVtYer9aASJkiEcQrr4L9ovolbV1hl9fKCG7g6i6-VQtTKZjt-uo91vBVsPsVmDUSFecAOU9yR58t4JA2kyf31_G8D45sGgEjQq%26wd%3D%26eqid%3Dc2df77f50001aebf00000005573e82ad&ecd=1&psr=1366x768&par=1366x728&pis=-1x-1&ccd=24&cja=false&cmi=6&col=zh-CN&cdo=-1&tcn=1463714511&qn=504c5c6cbdd32344&tt=1463714510710.26.144.145" width="728" height="90" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">
本文介绍了解决 Extjs4 中 Grid 组件在 TabPanel 中关闭后重新打开时报错 'Cannot read property 'addCls' of null' 的问题。通过调整 Grid 定义的方式,确保每次打开都能正确初始化。



547

被折叠的 条评论
为什么被折叠?




2楼 u010606441 2015-09-16 22:27发表 [回复]-
-
谢谢楼主,很好的解决 了我的问题,在我的问题中只要用initComponent:function()就可以解决了,并没有用到ext.apply,还有楼主所说的{xtype:'xxx'}这种形式,在代码里具体指什么样的形式,,
1楼 newbie_code 2014-10-11 11:48发表 [回复]-
-
很不错,对我的帮助很大