3

我想使用路由系统来提供后退按钮支持。我正在显示基于唱片店的项目列表。当我处理 itemtap 事件时,function(list, index, target, record)我得到了对所选记录的引用,我将其传递到我实例化并显示的新屏幕。

在这种情况下,我如何指示我已移动到新屏幕并启用后退按钮的历史管理器。我明白application.redirectTo了,但我会失去对我想使用的记录的引用。(redirectTo 会将一个新操作推送到历史堆栈中,其中包括记录的主要 id,但这似乎是多余的,因为当我处理重定向时,我需要根据 id 重新查找记录。)

有没有直接的方法来告诉历史对象前进到一个新的动作并启用后退按钮支持?

4

1 回答 1

1

我没有找到更容易的方法。这是我在我的应用程序中的操作方式(使用嵌套列表)。我用这样的路由创建了控制器:

Ext.define('MyApp.controller.ListItems', {
    extend: 'Ext.app.Controller',

    config: {
            refs: {
                    nestedList: '.nestedlist'
            },
            control: {
                    nestedList: {
                            itemtap: 'itemSelected'
                    }
            },
            routes: {
                    'item/:id': 'showListItem'
            }
    },

    list: null,
    index: null,
    target: null,
    record: null,
    showListItem: function( id ){
            var nestedList = this.getNestedList(),
                    store = nestedList.getStore(),
                    node = store.getById(id);
            if ( node.isLeaf() ){
                    nestedList.goToLeaf(node);
                    nestedList.fireEvent('leafitemtap', nestedList, this.list, this.index, this.target, this.record);
            } else {
                    nestedList.goToNode(node);
            }
    },
    itemSelected: function( nl, list, index, target, record ){
            this.list = list;
            this.index = index;
            this.target = target;
            this.record = record;
            var path = 'item/'+record.data.id;
            this.redirectTo(path);
    }
});

我还重写了嵌套列表的 onItemTap 方法,现在所有列表更改都是通过控制器和 propper 路由完成的。

onItemTap: function(list, index, target, record, e){
    this.fireEvent('itemtap', this, list, index, target, record, e);
}

希望它会有所帮助。写在这里,如果你找到更好的方法,请。

于 2013-05-21T14:23:20.380 回答