Extjs4---Cannot read property 'addCls' of null 或者 el is null 關於tab關閉後再開啟不顯示或者報錯
阿新 • • 發佈:2022-05-02
做後臺管理系統時遇到的問題,關於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方法設定進去,nnd,這個問題整了兩天,終於解決了