2014-09-04 84 views
1

我有一個組合的形式,我試圖找出一個簡單的方法將組合值傳遞給組合小部件。試圖通過initComponent傳遞參數到項目數組

基本上我穿過陣列到我的形式,如下所示:

var contentPanel = Ext.create('MyForm', { 
     countryCodesForCombo: _this.countryCodesForCombo, 
    }); 

這意味着數據來自通過initComponent方法。

Ext.define('MyForm', { 
    extend: 'Ext.form.Panel', 

    initComponent : function(){ 

     var cCodes = this.countryCodesForCombo; 

     this.callParent(); 
    }, 
    items: [ 
     { 
      fieldLabel: 'Hi', 
      xtype: 'combobox', 
      name: 'land', 
      displayField:'name', 
      store: { 
       fields: ['name'], 
       data: this.countryCodesForCombo // <--- want to get country codes somehow here 
      } 
     } 
    ] 
}); 

但是,這些值不能到達項目對象。

基本上我的問題是,如何通過initComponent方法將值傳遞給items數組?

+0

想想評價的順序。對象的整個RHS需要在它被定義之前進行評估。該類不存在,更不用說實例了。 – 2014-09-04 09:26:14

回答

2

您的店鋪看起來不錯。你必須創建一個商店對象。

這將工作:

Ext.define('MyForm', { 
    extend: 'Ext.form.Panel', 

    initComponent : function(){ 

     this.store = Ext.create('Ext.data.Store', { 
      fields: ['name'], 
      data: this.countryCodesForCombo 
     }); 

     Ext.apply(this, { 

        items: [{ 

         fieldLabel: 'Hi', 
         xtype: 'combobox', 
         queryMode: 'local', 
         name: 'land', 
         displayField:'name', 
         store: this.store      
        }] 
     }); 

     this.callParent(); 
    }, 

}); 

這裏是一個小提琴鏈接太:https://fiddle.sencha.com/#fiddle/9ru

+0

我的商店還行。我只是想知道是否有更清晰的方式來傳遞值到項目。使用Ext.apply(這個...)對我來說似乎有點混亂。 – 2014-09-04 09:03:09

+0

我覺得'Ext.apply(this,{..})'是好的,如果你不是很多。但我還是頭疼,直到我習慣了它。 – JuHwon 2014-09-04 09:10:41