2011-08-04 18 views
1

1-I使用下面的代碼來定義可重用的網格, 但是當我創建實例時,類定義中的任何配置都沒有破壞代碼的效果。是什麼原因? 3-在配置類聲明中是否有任何限制? 2-我如何在網格類中創建一些默認列並向其對象中添加更多列? 感謝定義一個可重用組件

Ext.define("IBS.users.Grid", { 
    extend: "Ext.grid.Panel", 
    config:{ 
     selType:'checkboxmodel',  //not work 
     dockedItems:[/* items */],  //break 
     multiSelect:true, 
     features: [ 
      { 
       groupHeaderTpl: '{name}', 
       ftype: 'groupingsummary' 
      }, 
      { 
       ftype:'filters', 
       encode: false, // json encode the filter query 
       local: true 
      } 
     ], 

     viewConfig: {  //not work 
      stripeRows: true, 
      filterable:true, 
      loadMask: false 
     }, 
     listeners : { 
      itemdblclick: function(dv, record, item, index, e) { 
       console.log(arguments); 
      } 
     } 
    }, 
    constructor:function(config) { 
     this.callParent(arguments); 
     this.initConfig(config); 
    //  this.self.instanceCount++; 
    } 
}); 

回答

0

1 - 我用下面的代碼來定義一個可重複使用的網格,但是當我做例如,在類定義沒有配置沒有任何破壞代碼的效果。是什麼原因?

我可以回答爲什麼你的配置不起作用。因爲config正在傳遞給cunstructor 不是您的默認配置。你必須運用你的默認配置,以使默認的配置有效:

constructor:function(config) { 
    config = Ext.applyIf(config, this.config); 
    this.callParent(arguments); 
    this.initConfig(config); 
} 

不過,我不知道爲什麼dockedItems:[/* items */]斷碼。也許你在/* items */的某個地方有語法或邏輯錯誤。

2-我如何在網格類中創建一些默認列並在其對象中添加更多 列?

這很簡單。只需覆蓋您initComponent功能:

Ext.define("IBS.users.Grid", { 
    extend: "Ext.grid.Panel", 
    // ... 
    initComponent : function(){ 
    if (!this.columns) { 
     // default columns: 
     this.columns = [{ 
     dataIndex: 'dkjgkjd', 
     // ... 
     }]; 
     // if we passed extraColumns config 
     if (this.extraColumns) 
     for (var i=0; i < this.extraColumns.length; i++) 
      this.columns.push(this.extraColumns[i]); 
    } 

    this.callParent(arguments); 
    }, 
    // ... 
}); 

3-有類配置聲明任何限制?

我不知道任何。但是,我不建議在類定義中聲明對象 configs。例如:

Ext.define("IBS.users.Grid", { 
    extend: "Ext.grid.Panel", 
    bbar: Ext.create('Ext.toolbar.Toolbar', // ... 
    // ... 
}); 

這將是第一個實例的類。但是,當你創建第二個實例時,bbar指的是與第一個實例相同的對象。因此bbar將從第一個網格中消失。
取而代之的是在initComponent中聲明對象配置。

+0

分子,非常感謝您的好回答, 如何使用initComponent在類定義中聲明對象配置? – PHPst

+0

@Reza,只需使用'this.neededConfig = {/ *您的對象在這裏* /};'就像在我的答案中顯示'columns'一樣。 –

相關問題