2013-02-28 60 views
0

我正在處理一個Extjs 4應用程序,我正處於需要動態創建視圖組件的地步。extjs 4:商店回調問題

我有一個商店,當我從一個組合框中選擇一個值時,加載了新項目。我想爲新商店的每件商品創建一個新的視圖組件。

我在使用Extjs 4和MVC架構。

這是創建當我選擇從另一個組合的項目多數民衆贊成一枚新型組合框的功能:

function createComboBox(label) { 
var combo = new Ext.form.ComboBox({ 
    displayField: 'combo', 
    typeAhead: true, 
    mode: 'local', 
    forceSelection: true, 
    triggerAction: 'all', 
    emptyText: 'Select item...', 
    selectOnFocus: true, 
    fieldLabel: label 
}); 
return combo; 
} 

這是我的「選擇組合框」處理事件中的代碼:

onSelectedValue: function (combo) { 
var selected = combo.getValue(); 
var guiDataStore = this.getGuiDataStore(); 
guiDataStore.getProxy().url = 'gui_comp_items.php?id_metric=' + selected; 
guiDataStore.load({ 
    params: { 
     id_metric: selected 
    }, 
    scope: this, 
    callback: function() { 
     var paramsRef = this.getParams();//this is the view where I'd like to create the combobox 
     var total = guiDataStore.getTotalCount(); 
     if (total > 0) { 
      guiDataStore.each(function (model) { 
       if (model.get('type_guicomp') == 'combobox') { 
        paramsRef.down('fieldset[id=filterfieldset]').add(createComboBox(model.get('name_filter'))); 
        paramsRef.down('fieldset[id=filterfieldset]').doLayout(); 
       } 
      }) 

     } 
    } 
}) 

}

所以我的問題是,我第一次從現有的組合框中選擇一個項目和total = 0,沒有創建組合框,一切都是好,那麼當我選擇返回total = 2的值時,會創建2個新的組合框,這是完美的。但是,當之後,我再次選擇一個值爲total = 0,商店沒有更新,我仍然得到2個新的組合框。

我的回調有問題嗎?請任何幫助,將不勝感激。

+2

一旦guiDataStore裏面有2條記錄,下次爲什麼會是空的?如在中,您是否在各種回撥呼叫之間清空商店? – Izhaki 2013-02-28 17:29:29

+0

謝謝!在回調工作後添加'guiDataStore.loadData([],false);' – salamey 2013-03-01 08:28:44

回答

0

一旦guiDataStore有2條記錄,下次爲什麼會是空的?

如在,您是否在各種回調調用之間清空商店?