Extjs如何参数化商店代理URL

时间:2019-05-07 13:59:26

标签: extjs

我是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。

我该如何解决?

2 个答案:

答案 0 :(得分:0)

签出the example on fiddle

  

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

答案 1 :(得分:0)

在第二次尝试中,您只是没有正确创建store config对象。

尝试一下:

data: {docID: docID}

查看此fiddle(第22行)。