私は Extjs 4 アプリケーションに取り組んでおり、ビュー コンポーネントを動的に作成する必要があるところまで来ています。
コンボボックスから値を選択すると、新しいアイテムが読み込まれるストアがあります。そして、新しいストアにある各アイテムに対して新しいビュー コンポーネントを作成したいと考えています。
MVC アーキテクチャで Extjs 4 を使用しています。
これは、別のコンボからアイテムを選択したときに起動される新しいコンボボックスを作成する関数です:
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 つの新しいコンボボックスが表示されます。
コールバックに問題はありますか? どんな助けでも大歓迎です。