您的位置:首页 > Web前端 > JavaScript

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

2016-05-20 11:26 651 查看
 


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

2013-03-28 07:15 5957人阅读 评论(2) 收藏 举报


 分类:
 

extJs(9) 


做后台管理系统时遇到的问题,关于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'}形式定义子组件




0

0
 
 

上一篇ExtJS
grid 的 tbar 显示不出来

下一篇extjs4
combo 的 键入自动查询

我的同类文章

extJs(9)

•Ext.js
4 combo 在 toolbar上显示问题2014-08-27阅读245
•EXT
combo setValue ,给combo 设默认值,常见诡秘问题2013-05-16阅读2037
•extjs4
combo 的 键入自动查询2013-04-02阅读1991
ExtJS嵌入网页要解决iframe自动适应窗体大小的问题2013-03-27阅读588
•extJs4
中 panel 的 setTitle 的 一个显示 BUG2013-01-25阅读989
•ext
中 设置 radioGroup 内 radio的值2013-11-05阅读1154
•ext.js
4.1 的 combo 的forceSelection 属性遇到BUG2013-04-16阅读2669
•ExtJS
grid 的 tbar 显示不出来2013-03-27阅读942
•extjs4
使用笔记 12013-03-27阅读1013

参考知识库




JavaScript知识库

2400关注|647收录




jQuery知识库

1084关注|262收录




AngularJS知识库

943关注|333收录

猜你在找

ArcGIS for JavaScript
Windows CE车载应用的实现与相关技术点
Struts实战-使用SSH框架技术开发学籍管理系统
HTML 5视频教程系列之JavaScript学习篇
基于J2EE实现Webservice项目实战ATM

<iframe 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.csdn.net%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;"></iframe>

查看评论

2楼 u010606441 2015-09-16 22:27发表 [回复]


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


很不错,对我的帮助很大
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: