Extjs4---Cannot read property 'addCls' of null 或者 el is null 关于tab关闭后再打开不显示或者报错

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

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

原因是我在定义grid的错误

这是错误代码:

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

应该改为这个:

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

看样子属性的设置都要用apply方法设置进去,nnd,这个问题整了两天,终于解决了

上一篇:Java面向对象----个人参考资料


下一篇:Java面向对象的封装