use extra params in store dynamically

前端 未结 5 2862
鱼传尺愫
鱼传尺愫 2021-02-20 17:59

I have a form. In the form, I am using a comboBox with a store.

{
    xtype: \'combobox\',
    id: \'SubContractor\',
    name: \'SubCo         


        
5条回答
  •  别跟我提以往
    2021-02-20 18:20

    Sorry guys,

    I've spent more time to understand all available options and the different. Too many answers about this problem. I've summarized them and hope the answer will help someone.

    When you create a store (Supported in Ext JS 6.x.x, probably in earlier versions):

    var store = Ext.create('YourStore', {
        listeners: {
            // Fires before a request is made. op is an Ext.data.Operation object
            beforeload:function(store,op){
                // Set request parameters (without overriding other parameters)
                op.setParams(Ext.apply(op.getParams()||{},{
                    par1:'value'
                }));
            },
            ... 
    

    When you define a proxy of a store. Supported since Ext JS 4.x.x:

    proxy: {
        type: 'ajax',
        url: 'rest/dse',
        extraParams: {
            par1: 'value'
        }
    

    Note: The params are sent for multiple subsequent queries in this case!

    When you load data explicitly. Supported in all versions of Ext JS (since 3.x.x):

    store.load({
        params: { par1: "value" }
    });
    

    Note: it is not needed to put par1 inside of ‘’ or “”.

    Alternative sub-option, which uses access to proxy and its extraParams option:

    store.getProxy().extraParams = {
        par1: 'value'
    };
    store.load();
    

    Be careful with this. This parameter is sent for multiple subsequent queries!

    When you create a store. Supported only in Ext JS 3.x version.

    var genres1 = new Ext.data.Store({
        baseParams: {
            param1: 'value1',
            param2: 'value2'
        },
        // ...
    

提交回复
热议问题