2014-09-04 81 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