Get values from localStorage to use in Sencha Touch AJAX Proxy

自闭症网瘾萝莉.ら 提交于 2019-12-06 10:51:04

问题


In my Sencha Touch application I store some values in localStorage and they get stored just fine. Later I need to use those values for a request to a store and I need to pass those values as request headers. The code looks like the following:

Ext.define('AppName.store.storeName', {
    extend: 'Ext.data.Store',

    requires: [
        'AppName.model.modelName'
    ],

    config: {
        model: 'AppName.model.modelName',
        storeId: 'storeName',
        proxy: {
            type: 'ajax',
            url: 'http://dynamic',
            headers: {
                auth_token: localStorage.getItem('activeUserToken'),
                user_email: localStorage.getItem('userEMail')
            },
            reader: {
                type: 'json'
            }
        }
    }
});

However, both auth_token and user_email values are being returned as "undefined" when in Chrome developer tools I clearly see those values. Besides of that I access those values in many other places in my Sencha Touch application but can't do that in the store itself.

Could anybody please tell me what I'm doing wrong?

Thanks


回答1:


I've solved this problem in the following way. Instead of passing the headers in the store I'm passing the headers during the request, before loading the store. Here's the code for that:

    Ext.getStore('storeName').getProxy().setUrl(someURL);

    Ext.getStore('storeName').getProxy().setHeaders(
         {
             "auth_token" : activeUserToken,
             "user_email" : userEmail
         }
    );

    Ext.getStore('storeName').load();

Hope this will help somebody else!



来源:https://stackoverflow.com/questions/12263457/get-values-from-localstorage-to-use-in-sencha-touch-ajax-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!