Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

extjs6 - Extjs 6: store extraParam propagated into record on save

I'm using ExtJS 6.5 to create a grid with a combobox in toolbar. The combobox have a store bound in a specific viewmodel. When selecting an option, the grid will refresh(POST) with a beforeload listener in the viewmodel's store, by adding an extraparam to the store proxy. Which works fine. But, when i'm trying to edit one record bound to the grid, even thou before the request (PUT) the record looks fine, when record.save() the extraparam will be sent as a parameter of the record. The code looks something like this:

items:[
    {
        xtype: 'grid',
        

        bind: {
            store: '{gridstore}'
        },
        tbar: [
            {
                xtype: 'combobox',
                fieldLabel: false,
                reference: 'some_selection',
                width:100,
                
                bind: {
                    store: '{cat}'
                },
                
                listeners: {
                    change: 'reloadStore'
                }
            }
        ],
        columns: [
            {
                dataIndex: 'name',
                text: 'Name',
                align: 'left',
                flex: 1,
                minWidth: 150
            },{
                dataIndex: 'soemthing',
                text: 'Something',
                align: 'left',
                flex: 1,
                minWidth: 150
            }]}

The viewmodel:

stores: {
    gridstore: {
        model: 'Model',
       
        listeners: {
            beforeload: function (store){
                var category = Ext.ComponentQuery.query('[reference="some_selection"]')[0],
                    category_value = category.value;

                store.getProxy().extraParams = {
                    category: category_value
                }
            }
        }
    },
    cat: {
        fields: ['cat'],
        data: [
            ['One'],
            ['Two'],
            ['Three'],
            ['Four'],
            ['Five']
        ]
    }

}

On edit:

view.add({
            xtype: form_panel,
            modal: true,
            viewModel: {
                data: {
                   
                    currentRecord: record 

                }
            }
        });

On save:

record.save({
        success: function(response, operation) {

           console.log(response)
        }
    });

I found an workaround by removing the extraparam on load listener on store:

load: function (store) {
                if (!store.isLoading())
                    delete store.getProxy().getExtraParams()['category'];
            }

I know the record's store have the extra parameter, but why is it sent when saving the record?

question from:https://stackoverflow.com/questions/65937378/extjs-6-store-extraparam-propagated-into-record-on-save

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...