2011-03-22 63 views
3
  1. 時,如何爲L設定值的組合框尋找負載監聽器,當組合框起來,負載將被調用,瓶坯的AJAX到服務器爲組合框取正確的顯示值。 但是,加載函數永遠不會被調用..我該如何解決它?ExtJS的:我加載

  2. 我想在組合框之前顯示文本,所以我添加了屬性fieldLabel: 'Save logs to:'。但文字不顯示。

THX, 號Yoni

this.log_save_combo = new Ext.form.ComboBox 
    ({ 
     store: ['Device', 'USB1', 'USB2'] 
     , id: 'cplogs_log_save_combo' 
     , name: 'cplogs_log_save_combo' 
     , triggerAction:'all' 
     , fieldLabel: 'Save logs to:' 
     , editable: false 
     //, value: "Device" 
     , listeners: { 
       'load': function(){ 
         alert("in load function"); 
       } 
    }); 

回答

0

沒有一個組合負載事件..所以是沒有得到執行,你寫的代碼。你已經有了一個用值定義的商店..你是否試圖將新值加載到連接到組合框的商店?你的意思是「組合框到底是什麼」?

要從服務器加載包含值的組合框,您只需加載商店。關於如何加載組合框請參考this article

----------------------------------------- UPDATE ---- -------------------------------------

  1. 您是否試圖加載形式與價值?在這種情況下,您可以使用BasicFrom提供的加載方法加載值。請參閱this example。即使它使用XML,您也可以輕鬆更改以從JSON加載數據。

  2. 爲了顯示標籤字段,您需要在容器的佈局屬性設置爲

    佈局:「形式」

+0

嗨,我在DB現在的儲蓄選擇的組合框的值。所以我想要顯示的是組合框的頁面已經啓動。我會檢查你所引用的文章,Thx – batz107 2011-03-22 09:58:53

1

一個,我想做的事在呈現組合框時,將從商店中選擇一個默認值。將組合框的值設置爲商店的第一個值已經工作得很好。

Ext.create('Ext.form.field.ComboBox', { 
... 
value : this.myStore.first().get('aFieldName') 
+0

的作品。謝謝.. – 2012-08-15 13:33:04

3

作爲一般的解決問題的辦法,我已經與

listeners:{ 
    scope: this, 
    afterRender: this.selectFirstComboItem 
} 

selectFirstComboItem: function(combo) { 
    // This will tell us if the combo box has loaded at least once 
    if (typeof combo.getStore().lastOptions !== "undefined") { 
     // Grab the first value from the store 
     combo.setValue(combo.getStore().first().get(combo.valueField)); 
    } 
    else { 
     // When the store loads 
     combo.getStore().on("load", function(store, items){ 
      // Grab the first item of the newly loaded data 
      combo.setValue(items[0].get(combo.valueField)); 
     }); 
    } 
} 
0
  1. 首先負載商店與store.load()
  2. 在回調設置的值與setValue()

實施例:

store.load({ 
     callback: function() { 
      form.findField('name_of_the_combo').setValue('your_value'); 
     } 
    }); 
0

沒有爲組合沒有加載事件。你可以做的是從你的表單加載的商店中加載數據。之後,您可以在組合選擇事件上設置字段級別。

例子:

listeners:{ 
    select: function(){ 
     Ext.getCmp('id_of_the_field') 
     .getEl() 
     .down('label.x-form-cb-label') 
     .update('Save logs to:');        
    } 
}