2013-02-18 33 views
0

我在這裏有兩個分機組合框,當combobox1選擇事件調用時,我需要更改第二個組合框的值,我的問題是我不知道如何改變組合框的模型。如何從其定義的外部更改組合框(Ext JS)的模型

items: [{ 
     xtype:'combo', 
     fieldLabel: 'Course', 
     afterLabelTextTpl: required,  
     store: new Ext.data.SimpleStore({ 
      data: [ 
       [1, 'Bsc CS'], 
       [2, 'MSc CS'], 
      ], 
      id: 0, 
      fields: ['value', 'text'] 
     }),    
     name: 'first', 
     listeners:{ 

      select: function(combo, records, eOpts) 
      { 
       if(this.getValue()=="Bsc CS") 
       { 
       // Ext.get('semcombo').getStore.loadData(msc); 
       } 
       else if(this.getValue()=="MSc CS") 
       { 

       } 
      } 

     }, 
     editable:false, 
     allowBlank: false 
    },{ 
     xtype:'combo', 
     fieldLabel: 'Semester', 
     id : 'semcombo', 
     afterLabelTextTpl: required, 
     name: 'last', 
     allowBlank: false, 
    } 
+0

您是什麼意思的模型?記錄? – Reimius 2013-02-18 20:41:58

+0

是的。我認爲模型是適合的。 – Bijoy 2013-02-19 04:57:12

+0

那麼......模型實際上是定義單個記錄結構的對象。技術上這個術語是可以互換的,但在這種情況下,記錄更清晰。 – Reimius 2013-02-19 14:28:52

回答

0

對於第二個組合框,爲每個模型類型配置一個組合框。在第一個組合框中進行選擇時隱藏或顯示相應的組合框。

0

如果需要變化數據完全(JSFiddle

select: function(checkbox,records) { 
     comp.clearValue(); 
     comp.bindStore(Ext.StoreMgr.lookup(records[0].data.store)); 
     // you can change the value field if needed 
     comp.displayField = 'petname'; 
     // you can change the display field if needed 
     comp.valueField = 'id'; 
     // you can change the display template if needed 
     comp.displayTpl = new Ext.XTemplate(
      '<tpl for=".">' + 
       '{[typeof values === "string" ? values : values["' + comp.displayField + '"]]}' + 
       '<tpl if="xindex < xcount">' + comp.delimiter + '</tpl>' + 
      '</tpl>' 
    ); 
     comp.picker = null; 
} 

如果你只是需要過濾(負載)在第二COMBOX的數據,你可以做這樣的事情

在第一個組合框的選擇事件準備第二個過濾數據

combobox2.queryData = [{ property: 'fieldName', value: value}]; 
combobox2.reset(); 
combobox2.doQuery(combobox.queryData); 

其中combobox2是對組合的參考,value是組合的屬性值。爲確保使用您的新查詢,請使用

combobox2.on('beforequery', function (e) { 
    e.query = e.combo.queryData; 
}); 
相關問題