简体   繁体   中英

How to update a Ext.form.ComboBox store (simple store) once created in a Ext.window (Extjs)

I tried the find a solution of my case on the sencha forms, but no success :(

I'm a beginner on js and Extjs 3.4, I'm trying to use Ext.form.ComboBox in a Ext.window to show the list of js objects (layers). the problem is when I create the window the first time and I click on the ComboBox trigger I get my layers list correctly, but when I remove or add a layer, and I click again on the trigger the store don't update and I find the same list :(((

Can you please help me to find a solution to this problem, for example when I click on the trigger it will update and load the new list store ? Any suggestion is welcome,

Thank you in advance !

Here is a part of the code :

createWindow: function() {
        var FIELD_WIDTH = 250,
            base = {
                forceSelection: true,
                editable: true,
                allowBlank: true,
                triggerAction: 'all',
                mode: 'local',
                labelSeparator: OpenLayers.i18n("labelSeparator"),
                valueField: 'value',
                displayField: 'text',
                labelWidth: 300
        };

        var addComboxFieldItemsWCS = function()  {
            layer_liste_WCS = [];
            var empty = true ;
            layerStore.each (function (record) {
                var layer = record.get('layer');
                var queryable = record.get('queryable');
                // var type = record.get('type');
                var hasEquivalentWCS = record.hasEquivalentWCS()
                if (queryable && hasEquivalentWCS) {
                    empty = false;

                    var ObjectRecordType = Ext.data.Record.create(['text', 'value']);
                    var rec = new ObjectRecordType({ text: layer.name, value:record })

                    console.log(rec.data.value)

                    var liste = [rec.data.text, rec.data.value];
                    layer_liste_WCS.push(liste)
                }
            }) ;
            if (empty)  {
                var ObjectRecordType = Ext.data.Record.create(['text', 'value']);
                var rec = new ObjectRecordType({ text: "No based WCS layer !", value:"" })

                var liste = [rec.data.text, rec.data.value];
                layer_liste_WCS.push(liste)
                disabled: true

            }
        };
        addComboxFieldItemsWCS();

        var WCS_store = new Ext.data.SimpleStore({
                        autoLoad: true,
                        fields: ['text','value'],
                        data: layer_liste_WCS
                        });

        ImageField = new Ext.form.ComboBox(Ext.apply({
            name: "Image_ref",
            fieldLabel: OpenLayers.i18n("Spot Image Input (Required)"),
            // fieldLabel: WPS_config.img.title, // From WPS Server
            emptyText: OpenLayers.i18n("Select your Image"),
            autoDestroy: true,
            width: FIELD_WIDTH,
            triggerAction: 'all',
            queryMode: 'local',
            store: WCS_store,
        }, base));

        return new Ext.Window({
            title: OpenLayers.i18n("addon_wpsjussie_title"),
            closable: true,
            resizable: false,
            shadow: false,
            closeAction: 'hide',
            region: "center", //"north","south","east","west"
            width: 480,
            height: 190,
            iconCls: 'wind_icon',
            plain: true,
            layout: 'border',
            buttonAlign: 'right',
            layout: 'fit',
            listeners: {
                show: function() {
                    this.el.setStyle('left', '');
                    this.el.setStyle('top', '');
                }
            },
            items: [{
                region: 'center',
                xtype: 'tabpanel',
                activeTab: 0,   
                width: 50,
                height:20,
                items: [{ // we will declare 3 tabs
                    title: OpenLayers.i18n('Datas Inputs'),
                    closable:false,
                    iconCls: 'input_icon',
                    active: true,
                    items:[{
                        xtype: 'form',
                        autoWidth: true,
                        labelWidth: 185,
                        bodyStyle: "padding:10px;",
                        items: [
                            ImageField,
                        ]                        
                    }]
                }]    
            }],                      
        });
    },

first you need to set up a 'click' listener. Every time it's performed, you have to reload the store 'WCS_store' :

WCS_store.load({ params: { param_1: value_1, param_2: value_2, etc...} });

Let me know if It works.

Here is the solution !

store: myArrayStore,
           listeners:
           {
               beforequery:function() {
                   addComboboxItemsWFS();
                   this.store.clearData();
                   this.store.loadData(my_data);
                }
           }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM