extjs store.load传递授权标头没有流入

sol*_*ssf 0 ajax proxy extjs request-headers

我试图Authorization: 'Bearer <TOKEN>'通过参数传入标题到我的store.load(),它不起作用.

如果我这样做,它的工作原理如下:

Ext.define('ExtApplication4.model.MenuListModel', {
    extend: 'ExtApplication4.model.Base',
    requires: [
        'ExtApplication4.model.Base'
    ],
    fields: [
        {
            name: 'text',
            type: 'string'
        },
        {
            name: 'iconCls',
            type: 'string'
        },
        {
            name: 'className',
            type: 'string'
        }
    ],
    proxy: {
        type: 'ajax',
        url: 'http://xxxxx/xxx/api/user/getusermenus/',
        reader: {
            type: 'json',
            rootProperty: 'data'
        },
        headers: {
            Authorization: 'Bearer ' + Ext.decode(Ext.util.Cookies.get('token'))
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

问题是我想填充我的授权标题store.load().我花了好几个小时试图找到这样做的语法.我尝试标题的所有内容都没有添加.

有人能告诉我怎么做吗?

这是我试过的:

targetStore.load({
    params: {
        username: uname
    },
    //headers: {            
    //    Authorization: 'Bearer ' + token;
    //},
    callback: function (records, operation, success) {
Run Code Online (Sandbox Code Playgroud)

Ale*_*der 6

你不能在你的负载中做到这一点,就像你不能在你的负载中提供其他额外的.在加载时,您只能覆盖一小部分配置,但几乎不是全部.您必须在加载之前设置它:

store.getProxy().setHeaders({
    Authorization:'Bearer ' + ...
});
store.load({
    ...
Run Code Online (Sandbox Code Playgroud)

如果setHeaders is not a function在您的ExtJS版本中,您可以设置

store.getProxy().headers = {
    Authorization:'Bearer ' + ...
};
Run Code Online (Sandbox Code Playgroud)