【问题标题】:Sencha touch list itemtap after view change视图更改后的 Sencha 触摸列表 itemtap
【发布时间】:2014-09-03 07:59:37
【问题描述】:

在 sencha touch 应用程序中,我得到了视图,其中一个包含一个列表。

如果我从包含列表的视图切换到另一个视图并返回,列表 itemtap 事件不会再次触发。

我对列表的看法:

Ext.define('app.view.ItemList', {
extend: 'Ext.navigation.View',
xtype: 'listitems',

config: {
    title: 'List',

    items: [
    {
        xtype: 'toolbar',
        ui: 'light',
        docked: 'top',
        title: 'List',
        items: [
            {
                xtype: 'button',
                text: 'Back',
                ui: 'back',
                handler: function() {

                    Ext.Viewport.animateActiveItem({xtype:'main'}, {type:'slide'});
                }
            },
        ]
    },
    {
        xtype: 'list',
        itemTpl: '{"name"}',
        store: {
            autoLoad: true,
            fields: ['name', 'email'],
            proxy: {
                type: 'rest',
                url: 'data/data.json',
                reader: {
                    type: 'json'
                }
            }
        }
    }]
},
initialize: function() {

    this.callParent();
}
})

控制器:

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

config: {
    refs: {
        listitems: 'listitems'
    },
    control: {
        'listitems list': {
            itemtap: 'showItem',
        }
    }
},
showItem: function(list, index, element, record) {

    this.getItemlist().push({

        xtype: 'panel',
        title: record.get('name'),
        html: [
            "<b>Name:</b> " + record.get('name') +
            "<b>Email:</b> " + record.get('email')
        ],
        scrollable: true,
        styleHtmlContent: true
    })
 }
 })

我也用 id、itemId 试过了,没用。

我该如何解决这个问题?

【问题讨论】:

  • 您确定点击事件不会再次触发吗?你的showItem函数包含什么,我希望它就像console.log('tapped')一样?
  • 您使用的是哪个版本的 ST,您介意在“sencha fiddle”中放一个最小的示例吗?
  • 你明白了,我检查了控制台,它每次都会触发,所以问题出在 showItem 函数上。我更新了问题以显示功能。
  • 以其他方式解决,但我很好奇问题出在哪里。
  • getItemlist() 返回的是什么?我从来没有在任何地方看到过这样的代码(至少不工作)。通常你会Ext.create 一个视图。

标签: extjs sencha-touch


【解决方案1】:

请这样尝试:

this.getItemlist().push(
    Ext.create('Ext.panel.Panel,{
        title: record.get('name'),
        html: [
            "<b>Name:</b> " + record.get('name') +
            "<b>Email:</b> " + record.get('email')
        ],
        scrollable: true,
        styleHtmlContent: true
    })
)

点击后退按钮时不要忘记使用getItemlist().pop()!在我的应用程序中,后退按钮没有(或并非总是)删除堆栈顶部的视图。添加负载掩码和 ActionSheets 时,情况会变得更糟。

【讨论】:

  • 基本上我在这里构建了完全相同的vimeo.com/37974749,然后我添加了一个简单的按钮来执行此操作:Ext.Viewport.animateActiveItem({xtype:'main'}, {type:'slide'});,但是当我从这里切换回列表视图并单击点击事件触发,但不加载项目
猜你喜欢
  • 1970-01-01
  • 2011-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-13
  • 1970-01-01
  • 2011-11-21
相关资源
最近更新 更多