2013-02-28 67 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条记录,下次为什么会是空的?

如在,您是否在各种回调调用之间清空商店?