【问题标题】:How to pass parameters to store in ExtJs如何传递参数以存储在 ExtJs 中
【发布时间】:2020-04-11 05:04:03
【问题描述】:

我正在处理需要绑定组合框但无法传递参数的显示器。下面是我的代码,请给我传递参数的方法。

//store
Ext.define('NetworkStore', {
    extend: 'Ext.data.Store',
    alias: 'NetworkStore',
    fields: ['Id', 'value'],
    storeId: 'NetworkStore', 
    autoLoad: true,
    proxy: {
        type: 'ajax',
        useDefaultXhrHeader: false,
        actionMethods: { create: "POST", read: "GET", update: "POST", destroy: "POST" },
        headers: { 'Content-Type': 'application/x-www-form-urlencode' },
        limitParam: false,
        startParam: false,
        pageParam: false,
        extraParams: {
            Style: 1
        },
        url: 'url',
        reader: {
            type: 'json'
        }
    }
});

xtype: 'combo',
name: 'NetworkIDList',
store: {
        type: 'NetworkStore',
        'Style': 3 //parameter
        //params: {  // tried this way as well but did not work for me.
        //  Style: 3
        //}
        }

注意:商店是在单独的文件中定义的。

【问题讨论】:

  • 您能解释一下您要达到的目标吗?为什么要绑定什么?
  • 我想将组合框与更新的存储绑定,因为我需要使用参数调用存储,并且我无法找到传递参数以进行 API 调用的方式。

标签: extjs store


【解决方案1】:

商店应该像下面的格式一样传递。

store: {
        type: 'NetworkStore',
        proxy: {
                extraParams: {
                    Style: 3
                }
            }
        }

【讨论】:

    【解决方案2】:

    您可以按如下方式更改参数:

    let store = Ext.data.StoreManager.lookup('NetworkStore'),
    
        // params are part of the proxy, not the store
        proxy = store.getProxy(),
    
        // make sure you keep the other params
        newParams = Ext.apply(proxy.getExtraParams(), {style: '3'});
    
    // set the params to the proxy    
    proxy.setExtraParams(newParams);
    
    // do whatever you plan to do with the store
    store.load();
    

    如果你想绑定一个值来存储代理参数,看看这个fiddle

    【讨论】:

    • 我想直接把它绑定到combobox,我们定义它的store属性。
    • 你看小提琴了吗。在小提琴中,我展示了如何将 extraParam 属性(样式)绑定到商店。您可以对组合框值执行相同操作。如果您不知道如何绑定组合框值,请这样写。
    猜你喜欢
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    相关资源
    最近更新 更多