首页 > 解决方案 > extjs how to pass parameters to a web rest api request

问题描述

I'm now trying to connect Extjs with a web rest api apart from my project. This is my view:

    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());
        }
});

Here is my model:

        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'
                },
                ...
            ]
        });

and my store:

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!!!')
    }
});

I'm trying to fetch resources from my apiurl which is a web rest api. I need to send some parameters, this code returns me the desired data, but this approach ignores the extraParamas at all. I can't tell that I went into the documentation and found how to use Extjs with a rest api becasue I was unable to find how to do that in the official documentation, so, I've been googleing for a solution and what I've made so far is getting code snippets from here and there. My question: how to send paramenters to a rest api? what am I doing wrong?

标签: extjs

解决方案


你的代码中有一个错字,extraParam a s,什么时候应该是extraParams


推荐阅读