【问题标题】:Sencha Touch: dynamically load Ext.List with parametric storeSencha Touch:使用参数存储动态加载 Ext.List
【发布时间】:2014-08-02 06:32:41
【问题描述】:

我有一个 Ext.List 显示某个帐户的帐户历史记录,对于每个帐户我加载自己的历史记录记录,例如,从以下网址:www.mysite.com/accounts/loadHistory?=accountId(或通过 POST 请求,没关系)。

在进入视图时为每个帐户重新加载数据的最佳做法是什么?

我现在的做法是这样的:

当进入视图时:

var store = Ext.getStore(storeId);

  1. store.removeAll(); // 删除数据,这样在重新加载新帐户的数据之前不会显示旧帐户的历史记录

  2. store.setParams(id).load(); //加载账户数据

查看:

 Ext.define('myApp.view.AccountHistory', {

    extend: 'Ext.List',

    xtype: 'accounthistory',

    config: {
        store: 'accountHistoryStore',
        emptyText: 'No history available',
        itemCls: 'expandedListItem',
        itemTpl: Ext.create('Ext.XTemplate',
            '<p>{accountId} - {accountText}</p>')
    },

    initialize: function() {

        this.callParent(arguments);

        var accountData = this.config.accountData; // parameter passed to view

        var store = Ext.getStore('accountHistoryStore');
        store.removeAll(); // remove current store records so the old account's info is not shown till the new account is loaded
        store.setParams(accountData.id); // set new proxy url 
        store.load(); // reload history for new account

    }

});

商店:

Ext.define('eMaliApp.store.ChildActivities', {

    extend: 'Ext.data.Store',

    requires: [
        'myApp.model.AccountHistory'
    ],

    config: {
        model: 'myApp.model.AccountHistory',
        storeId: 'accountHistoryStore',
        proxy: {
            type: 'ajax',
            url: myApp.utils.Config.getBaseUrl() + 'account/history',
            method: 'post'
            reader: {
                type: 'json',
                rootProperty: 'history'
            }
        }
    }

});

【问题讨论】:

    标签: extjs sencha-touch sencha-touch-2 sencha-touch-2.1


    【解决方案1】:

    这取决于您的工作流程。但是,当用户想要查看他的帐户历史记录时,您也可以通过他的帐户 ID(或其他任何内容)过滤商店,而不是从商店中删除所有商品。因此,如果用户返回他的帐户历史记录,您将无需再次加载其数据。

    【讨论】:

    • 我想到了这个,但是如果我有很多用户怎么办?如果我想加载大块的历史活动怎么办?不确定这是最佳做法。
    • 没有最佳实践。这始终取决于您的实际工作流程。
    猜你喜欢
    • 2012-01-15
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2013-04-14
    • 1970-01-01
    相关资源
    最近更新 更多