【问题标题】:How can I change/add params on a store如何在商店中更改/添加参数
【发布时间】:2011-05-25 07:03:22
【问题描述】:

在煎茶上,这是我的商店声明

Ext.regStore('newsStore',  {
    model: 'News',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: '../news/list.form?format=json',
        reader: {
            type: 'json',
            root: ''
        }
    },                        
});

如何修改参数?我试过了

params:{ format: 'json'}

但它不起作用!

【问题讨论】:

    标签: sencha-touch extjs


    【解决方案1】:

    商店声明

    new Ext.data.Store({
    model:'prj.models.ContactInfo',
    storeId:'contactInfoId',
    proxy:{
        type:'ajax',
        url:'/GetContactInfoByID',
        reader:{
            type:'json'
        },
        extraParams:{
            format:'json'
        },
        listeners:{
            exception:function(proxy, response, orientation){
                console.error('Failure Notification', response.responseText);
                Ext.Msg.alert('Loading failed', response.statusText);
            }
        }
    }   
    });
    

    将参数添加到代理和读取 ajax 存储

    prj.stores.contactInfoId.getProxy().extraParams.partyID = options.partyID;
    prj.stores.contactInfoId.getProxy().extraParams.eventName = options.eventName;
    prj.stores.contactInfoId.read();
    

    希望这会有所帮助。

    【讨论】:

    • 它有效,非常感谢。它完美,正是我正在寻找的:)。我需要有初始化参数并通过选项/按钮进行更改。谢谢你。 store 对象上的方法 read() 和 load() 有什么区别?
    • 两者具有相同的功能,即进行 ajax 调用并填充存储。使用 load 你有可选的配置对象,在加载之前传递给 Ext.data.Operation 对象。
    • 在 Sencha Touch 2.0.1.1 proxy.extraParams = {...} 不工作。请改用 proxy.setExtraParams({...})。
    【解决方案2】:

    动态设置额外参数:

    如果你想一次设置单个参数,你可以使用以下

    var proxy= myStore.getProxy();
    proxy.setExtraParam('param1', 'value 1' );
    proxy.setExtraParam('param2' , 'value 2' );
    myStore.load();
    

    如果要一次设置多个参数,可以使用以下

    proxy.setExtraParams({
         'param1':'value 1',
         'param2':'value 2'
    });
    

    【讨论】:

      【解决方案3】:

      你可以试试extraParams:

      Ext.regStore('newsStore',  {
          model: 'News',
          autoLoad: true,
          proxy: {
              type: 'ajax',
              url: '../news/list.form',
              reader: {
                  type: 'json',
                  root: ''
              },
              extraParams: {
                  format: 'json'
              }
          },                        
      });
      

      【讨论】:

      • 它有效。您知道如何修改参数吗?我这样检索商店: Ext.StoreMgr.get('newsStore').load();有可能改变extraParams吗? (Ext.StoreMgr.get('newsStore').proxy.extraParams....?)
      • 好的,由 mehul9595 回答(在这篇文章中)
      【解决方案4】:

      我建议您使用更优雅的解决方案,即 Sencha 方法:

      //Take your store
      var store = Ext.StoreMgr.get('YOUR_STORE_ID');
      
      //Apply the params
      Ext.apply(store.getProxy().extraParams, {
          partyID: options.partyID,
          eventName: options.eventName
      });
      
      //Reload your store
      store.contactInfoId.read();
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2015-05-26
        • 2011-10-18
        • 1970-01-01
        • 2022-08-17
        • 1970-01-01
        • 2017-04-20
        • 2016-09-06
        • 2019-11-15
        • 1970-01-01
        相关资源
        最近更新 更多