簡體   English   中英

如何將選定的extjs組合值設置為另一個組合框

[英]How to set selected extjs combo value to another combobox

我有兩個Extjs Comboboxes

var cb1 = new Ext.form.ComboBox({
    fieldLabel: 'Combobox1',
    width: 100,
    listeners:{
         scope: this,
         'select': this.reset
    }
});
var cb2 = new Ext.form.ComboBox({
    fieldLabel: 'Combobox2',
    width: 100,
    baseParams: { loadInitial: true, cb1Val: this.cb1.getValue() } // Here I want to get selected value of cb1
    listeners:{
         scope: this,
         'select': this.reset
    }
});

我正在使用this.cb1.getValue()獲取cb1選定值,但是我在這里得到空白值。

誰能告訴我我在做什么錯。

我認為組合2無法獲得組合1的值,因為您在baseParams中調用其值時未加載組合1。 我會根據您的情況推薦這種方法-

    var cb1 = new Ext.form.ComboBox({
        fieldLabel: 'Combobox1',
        width: 100,
        **id : "combo_1",**  // ID property added 
        listeners:{
             scope: this,
             'select': this.reset
   } });

// Previous code 
...

    listeners : {
        select : function(combo, rec, rind) {
             var combo2_val = Ext.getCmp("id_of_combo_1").getValue();
    }

在此,在第二個組合的選擇渲染器上,應該在combo2_val設置第一個的值。 更精確地說,您還可以為組合1設置默認值。您可以直接使用變量cb1來代替ID,而不必使用ID。

希望這能給您一個方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM