【问题标题】:Extjs how to parametrize the store proxy urlExtjs如何参数化商店代理url
【发布时间】:2019-05-07 13:59:26
【问题描述】:

我是 extjs 新手,我正在尝试参数化商店代理 url。

在我看来,我正在建造这样的商店:

store: Ext.create('mystore', {
                partofurl: 'url'
            })

还有我的商店:

Ext.define('mystore', {
    extend: 'Ext.data.Store',
    alias: 'store.mystore',
    model: 'mymodel',
    restful: true,
    autoLoad: true,
    proxy: {
        type: 'ajax',
        headers: {
           'Accept': '*/*',
           'Cache-Control': 'no-cache',
           'Content-Type': 'application/json',
           'Authorization': localStorage.token
        },
        reader: {
            type: 'json',
            rootProperty: 'data',
            successProperty: 'success'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            encode: true,
            rootProperty: 'data'
        },
        actionMethods: {
           read: 'GET'
        },
        api: {
           read: 'http://url' + this.partofurl,
           create: 'http://url' + this.partofurl,
           update: 'http://url' + this.partofurl,
           destroy: 'http://url' + this.partofurl,
        },
        autoSave: true
    }
});

我也试过这个:

store: Ext.create('mystore', {
                    proxy.api.read = 'http://url' + partofurl
                })

等等……但它一直在告诉我:

未捕获的错误:您正在使用 ServerProxy,但尚未为其提供 url。

我该如何解决这个问题?

【问题讨论】:

标签: extjs


【解决方案1】:

查看the example on fiddle

您不能在 Ext.define 中使用 this。 您需要在构造函数中设置 url 或覆盖 buildUrl 方法。

【讨论】:

    【解决方案2】:

    在您第二次尝试时,您只是没有正确创建商店配置对象。

    试试这个:

    var store = Ext.create('mystore', {
        proxy: {
            api: {
                read: 'http://url' + partofurl
            }
        }
    });
    

    查看fiddle(第 22 行)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多