文章出處

做后臺管理系統時遇到的問題,關于tab關閉后再打開不顯示,或者報錯

我在新的tabpanel中加入了一個grid,當我關閉再次打開就會報錯Cannot read property 'addCls' of null,

原因是我在定義grid的錯誤

這是錯誤代碼:

 

[javascript] view plaincopy
 
  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 plaincopy
 
  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方法設置進去,nnd,這個問題整了兩天,終于解決了


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()