0
votes

I should load date from server dynamically,

however, I have no idea how to change get parameters.

Here is my code.

I want to load store when the view is loaded, but the store get data from server

when the app is loaded. I need to change param according to user's input data.

[Store]

Ext.define('APP.store.MyTestStore', {
extend: 'Ext.data.Store',
requires: [
    'APP.model.MyModel',
],
config: {
    model: 'APP.model.MyModel',
    autoLoad: false,
    storeId : 'MyTestStore',
    proxy: {
        type: 'jsonp',
        method: 'GET',
        // extraParams: {
        //     man: '',
        // },
        url: 'http://test.com/api/test/',
        reader: {
            type: 'json',
            rootProperty: 'apiList'
        }
    }
},

});

[VIEW]

Ext.define('APP.view.MyListView', {
extend: 'Ext.navigation.View',
xtype: 'applistview',
requires: [
    'Ext.Panel',
    'APP.view.TopMenu',
    'APP.view.TestListView',
    'APP.config.Runtime',
],
fullscreen: true,
config: {
    navigationBar: false,
    fullscreen: true,
    items: [
        {   // Top Menu
            xtype: 'topmenu',
        },
        {   // Main Menu
            xtype: 'tlist',
            itemId: 'myList',
            store: 'MyTestStore',
        },
        {   // Bottom Banner
            xtype: 'bottombanner',
        },
    ]
},
initialize: function(){
    var test = Ext.getStore('MyTestStore').load({extraParams:{man:'test'}});
    console.log(test);
}

});

1

1 Answers

0
votes

You can do this in two ways,

App default extra param set to 123

Ext.define('APP.store.MyTestStore', {
    extend: 'Ext.data.Store',
    requires: [
        'APP.model.MyModel'
    ],
    config: {
        model: 'APP.model.MyModel',
        autoLoad: false,
        storeId : 'MyTestStore',
        proxy: {
            type: 'jsonp',
            method: 'GET',
            extraParams: {
                man: '123'
            },
            url: 'http://test.com/api/test/',
            reader: {
                type: 'json',
                rootProperty: 'apiList'
            }
        }
    }
});

When loading the store you can change extra param like the following way

initialize: function(){

    var test = Ext.getStore('MyTestStore').getProxy().getExtraParams().man= '567'
    Ext.getStore('MyTestStore').load();
    console.log(test);

}

In Another way you can change proxy url without setting extra param

initialize: function(){
       var url = 'http://test.com/api/test/'; // your store proxy url 
       var modified = url+'parameter you get from user'
        Ext.getStore('MyTestStore').getProxy().setUrl(modified);
        Ext.getStore('MyTestStore').load();
        console.log(test);

    }