extjs如何将参数传递给Web Rest API请求

时间:2019-04-25 18:39:40

标签: extjs

我现在正在尝试将Extjs与我的项目之外的Web rest api连接起来。这是我的看法:

    Ext.define('mycomponents.view.comboselview', {
        extend: 'Ext.container.Container',
        id: 'comboview',
        alias: 'widget.comboview',
        xtype: 'comboview',
        requires: [
            'mycomponents.model.comboselmodel'
        ],
        items: [
            {
                xtype: 'combobox',
                reference: 'levels',
                publishes: 'value',
                fieldLabel: 'Choices',
                displayField: 'description',
                anchor: '-15',
                store: {
                    type: 'levels'
                },
                minChars: 0,
                queryMode: 'local',
                typeAhead: true,
                labelWidth: 100,
                labelAlign : 'right',
                width: 265,
                allowBlank: false
            }
        ],
        initComponent: function () {
            this.callParent(arguments);
            var that = this;
            console.log('!!!!!!!!!!!!!!!!!!!!!!>>>', that.up());
        }
});

这是我的模特:

        Ext.define('mycomponents.model.comboselmodel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                     name: 'id',
                     mapping: 'pk'
                },
                {
                     name: 'description',
                     type: 'string',
                     mapping: 'description'
                },
                {
                     name: 'levelid',
                     type: 'integer',
                     mapping: 'levelid'
                },
                ...
            ]
        });

和我的商店:

Ext.define('mycomponents.store.comboselstore', {
    extend: 'Ext.data.Store',
    alias: 'store.levels',
    model: 'mycomponents.model.comboselmodel',
    storeId: 'levels',
    restful: true,
    autoLoad: true,
    proxy: {
        type: 'ajax',
        headers: {
           'Accept': '*/*',
           'Cache-Control': 'no-cache',
           'Content-Type': 'application/json',
           'Authorization': localStorage.token
        },
        extraParamas: {
           sort: 'description',
           filter: {
               idlevel: {
                   'null': -1
               }
           }
        },
        reader: new Ext.data.JsonReader({
        }),
        writer: new Ext.data.JsonWriter({
        }),
        actionMethods: {
           read: 'GET'
        },
        api: {
           read: 'apiurl',
           create: 'apiurl',
           update: 'apiurl',
           destroy: 'apiurl'
        },
        autoSave: true
    },
    constructor: function (config) {
        this.callParent([config]);
        console.log('I am entering here!!!')
    }
});

我正在尝试从apiurl(这是一个Web Rest API)中获取资源。我需要发送一些参数,此代码返回了我想要的数据,但是这种方法完全忽略了extraParamas。我不能说我进入了文档,并找到了如何通过rest api使用Extjs,因为我无法在官方文档中找到如何做的方法,所以,我一直在寻找解决方案以及我的目标。到目前为止,我们正在从这里到那里获取代码片段。我的问题:如何将参数发送到休息API?我在做什么错了?

1 个答案:

答案 0 :(得分:1)

您的代码中有一个错字,extraParam a ,应该是extraParams