【问题标题】:sencha touch 2 - how to manipulate history supportsencha touch 2 - 如何操作历史支持
【发布时间】:2013-05-21 22:23:20
【问题描述】:

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

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

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

【问题讨论】:

    标签: sencha-touch sencha-touch-2


    【解决方案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 方法,现在所有列表更改都是通过控制器和属性路由完成的。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2013-08-21
      相关资源
      最近更新 更多