javascript 如何在运行时在 extjs 中更改代理的 extraParams 配置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6665970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:27:48  来源:igfitidea点击:

How to change the extraParams config of a proxy at runtime in extjs?

javascriptajaxextjs

提问by alex

I have the following store:

我有以下商店:

var store = new Ext.data.Store({
     model: 'Result',
     proxy: {
         type: 'ajax',
         extraParams: {search_term : term},
         url : 'find.pl'
     },
});

How can I change the parameters with which the url is called (ex. search_term) at runtime?

如何在运行时更改调用 url 的参数(例如 search_term)?

回答by Amol Katdare

Think about it as -
You don't callthe URL. You loadthe store.

把它想象成 -
你不调用URL。你加载商店。

Now, you can specify search_term value whenever you try to load the store using something like -

现在,每当您尝试使用以下内容加载商店时,您都可以指定 search_term 值 -


store.load({
    params:{
        search_term:'my runtime search term'
    }
    //other options like a callback function, append/add flag, etc. 
});

回答by Ankit

Assuming that you want to change the parameters after defining the storevariable. It obviously will depend whether Ext.data.Storeallows the parameters to be changed. If it allows then it is as simple as: store.proxy.extraParams.search_term = //something

假设您要在定义store变量后更改参数。这显然取决于是否Ext.data.Store允许更改参数。如果允许,那么它很简单: store.proxy.extraParams.search_term = //something

回答by aswininayak

var form = this.up('form').getForm();
              var searchText = form.getValues('search_term').split("=")[1];
              var resultGrid = Ext.widget('ResultGrid');
              var store = resultGrid.getStore();
                  if (searchText != undefined && searchText != '') {
                      store.proxy.extraParams.bomId = searchText;
                  }
              resultGrid.store.load();
              }

回答by DarkKnightFan

store.proxy.extraParams.search_term = 'any value'; //set extraparams field
store.load() //load the store

But need to take care with IE8.. check this

但需要注意 IE8 ..检查这个