Extjs4---Cannot read property 'addCls' of null

本文介绍了解决 Extjs4 中 Grid 组件在 TabPanel 中关闭后重新打开时报错 'Cannot read property 'addCls' of null' 的问题。通过调整 Grid 定义的方式,确保每次打开都能正确初始化。
 

Extjs4---Cannot read property 'addCls' of null

  5957人阅读  评论(2)  收藏  举报
  分类:
 

做后台管理系统时遇到的问题,关于tab关闭后再打开不显示,或者报错

我在新的tabpanel中加入了一个grid,当我关闭再次打开就会报错Cannot read property 'addCls' of null,

原因是我在定义grid的错误

这是错误代码:

[javascript]  view plain copy
  1. Ext.define('HT.view.Grid',{  
  2.     extend:'Ext.grid.Panel',  
  3.   
  4.     title : '人员列表',  
  5.     width:400,  
  6.     height:170,  
  7.     frame:true,  
  8.     store: {  
  9.         fields: ['id','name','sex','age','birthday'],  
  10.         proxy: {  
  11.             type: 'ajax',  
  12.             url : 'users',  
  13.             reader: {  
  14.                 type: 'json',//Ext.data.reader.Json解析器  
  15.                 root: 'users'  
  16.             }  
  17.         },  
  18.         autoLoad: true  
  19.     },  
  20.     columns: [//配置表格列  
  21.         new Ext.grid.RowNumberer(),//表格行号组件  
  22.         {header: "编号", width: 80, dataIndex: 'id', sortable: true},  
  23.         {header: "姓名", width: 80, dataIndex: 'name', sortable: true},  
  24.         {header: "年龄", width: 80, dataIndex: 'age', sortable: true},  
  25.         {header: "性别", width: 80, dataIndex: 'sex', sortable: true},  
  26.         {header: "生日", width: 80, dataIndex: 'birthdate', sortable: true}  
  27.     ]  
  28.   
  29. });  

应该改为这个:

[javascript]  view plain copy
  1. Ext.define('HT.view.Grid',{  
  2.     extend:'Ext.grid.Panel',  
  3.     title : '人员列表',  
  4.       
  5.     initComponent:function(){  
  6.         Ext.apply(this,{  
  7.             width:400,  
  8.             height:170,  
  9.             frame:true,  
  10.             store: {  
  11.                 fields: ['id','name','sex','age','birthday'],  
  12.                 proxy: {  
  13.                     type: 'ajax',  
  14.                     url : 'users',  
  15.                     reader: {  
  16.                         type: 'json',//Ext.data.reader.Json解析器  
  17.                         root: 'users'  
  18.                     }  
  19.                 },  
  20.                 autoLoad: true  
  21.             },  
  22.             columns: [//配置表格列  
  23.                 new Ext.grid.RowNumberer(),//表格行号组件  
  24.                 {header: "编号", width: 80, dataIndex: 'id', sortable: true},  
  25.                 {header: "姓名", width: 80, dataIndex: 'name', sortable: true},  
  26.                 {header: "年龄", width: 80, dataIndex: 'age', sortable: true},  
  27.                 {header: "性别", width: 80, dataIndex: 'sex', sortable: true},  
  28.                 {header: "生日", width: 80, dataIndex: 'birthdate', sortable: true}  
  29.             ]  
  30.         }),  
  31.         this.callParent(arguments);  
  32.     }  
  33.   
  34. });  

看样子属性的设置都要用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
 
 
我的同类文章

参考知识库

img
JavaScript知识库

img
jQuery知识库

img
AngularJS知识库

猜你在找
ArcGIS for JavaScript
Windows CE车载应用的实现与相关技术点
Struts实战-使用SSH框架技术开发学籍管理系统
HTML 5视频教程系列之JavaScript学习篇
基于J2EE实现Webservice项目实战ATM
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&ltu=http%3A%2F%2Fblog.youkuaiyun.com%2Fsuncaishen%2Farticle%2Fdetails%2F8731672&ltr=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;">
查看评论
2楼  u010606441 2015-09-16 22:27发表 [回复]
谢谢楼主,很好的解决 了我的问题,在我的问题中只要用initComponent:function()就可以解决了,并没有用到ext.apply,还有楼主所说的{xtype:'xxx'}这种形式,在代码里具体指什么样的形式,,
1楼  newbie_code 2014-10-11 11:48发表 [回复]
很不错,对我的帮助很大

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值