【问题标题】:Sencha Touch 2 Load store on demandSencha Touch 2 按需加载存储
【发布时间】:2012-07-24 11:47:44
【问题描述】:

目前我有一个商店,我正在运行时在我的 app.js 中加载:

stores: ['Neighbors']

它的 autoLoad 属性设置为 true。

我现在添加了一个登录系统,如果在 localStorage 中找不到某些信息,则会加载该系统:

//show login if user credentials are unknown
var username = window.localStorage.getItem("email");
var user_id = window.localStorage.getItem("user_id");

if(username == '' || username == undefined || user_id == '' || user_id == undefined) {
    Ext.Viewport.add(Ext.create('aa.view.Login'));
} else {
    Ext.Viewport.add(Ext.create('aa.view.Main'));
}

登录视图触发 ajax 请求以登录用户,成功时返回用户 ID 和其他一些信息:

onLoginButtonTap: function() {
        var values = this.getLoginForm().getValues();
        var that = this;
        // do the ajax login
        Ext.Ajax.request({
            url: 'http://localhost:8000/session',
            method: 'POST',
            params: values,
            timeout: 10000, // time out for your request

            success: function(result) {
                // let's get the email and id into local storage
                var json = Ext.decode(result.responseText);
                console.log(json);
                window.localStorage.setItem('user_id', json.user_id);
                window.localStorage.setItem('email', json.email);

                // var neighborsStore = Ext.getStore('Neighbors');
                // neighborsStore.load();


                // load up the tab holder and destroy the login view
                Ext.getCmp('loginForm').destroy();
                Ext.Viewport.add(Ext.create('aa.view.Main'));

            },

            failure: function(){
                Ext.Msg.alert("Login Failed");
            }
        });

    }

我使用商店中的 user_id 来获取附近其他用户的列表。唯一的问题是,除非我的用户已登录,否则我的 user_id 是未知的。

我要么需要刷新商店,要么需要将其加载推迟到成功登录之后。我宁愿做第二个选项,只在登录后尝试加载商店。

我似乎找不到任何有关如何执行此操作的信息。我试过了

Ext.getStore('storename').load() 

但它不会刷新商店。我尝试将 autoLoad 设置为 false,但商店永远不会加载。如何延迟加载?

【问题讨论】:

    标签: touch extjs store


    【解决方案1】:

    您应该可以在成功函数中使用that.getNeighborsStore().load()。一旦用户成功登录,这将加载商店。

    【讨论】:

    • 我得看看能不能再找到这段代码。这个项目被搁置了,但我很想看看这是否有效。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-01-15
    • 2012-06-12
    • 1970-01-01
    • 2014-05-25
    • 2012-09-13
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    相关资源
    最近更新 更多