【问题标题】:Sencha Touch: List ItemTap Event FiringSencha Touch: List ItemTap 事件触发
【发布时间】:2010-11-30 10:44:20
【问题描述】:

我正在密切关注GeoCongress.us App 中的代码,因为这是我的第一个 Sencha Touch 应用程序,该应用程序的布局功能背后的前提与我希望实现的类似。

我在获取 List 对象以响应 itemtap 事件时遇到问题。我的意图是在SetsScreen 级别捕获itemtap 事件,触发我自己的自定义事件,我的App 对象将侦听,然后App 可以处理显示新卡的过程(基于项目)。

首先,SetsScreen 对象(至少是它的相关部分):

DataSets.views.SetsScreen = Ext.extend(Ext.Panel, {
    cls: 'sets-screen',
    layout: 'card',

    initComponent: function() { 
        // Build the main content list and add it to the main scren
        this.setsList = new DataSets.views.SetsList({
            scroll: false
        });
        this.setsList.on('itemtap', this.onListItemTap, this);

        this.main = new Ext.Container({
            scroll: true,
            items: [this.setsList]
        });

        this.items = [this.main];
        DataSets.views.SetsScreen.superclass.initComponent.call(this);
    },

    onListItemTap: function(dv, index, item, e) {
        alert('Test');
    }
});

这是我的SetsList 对象(这里没什么了不起的):

DataSets.views.SetsList = Ext.extend(Ext.List, {
    itemSelector: '.sets-list-item',
    singleSelect: true,

    initComponent: function() {
        this.store = DataSets.stores.Sets;
        this.itemTpl = Ext.XTemplate.from('sets-list');

        DataSets.views.SetsList.superclass.initComponent.call(this);
    }
});

Sets 对象只不过是一个快速数据模型和 Ext.data.Store:

Ext.regModel('Sets', {
    idProperty: 'id',
    fields: [
        'title',
        'last_updated',
        'current_value'
    ]
});

DataSets.stores.Sets = new Ext.data.Store({
    model: 'Sets',
    data: [
        {id: 0, title: 'Weight', last_updated: new Date('11/28/2010 00:00:00 AM GMT-0600'), current_value: 145},
        {id: 1, title: 'Cups of Coffee', last_updated: new Date('11/28/2010 07:00:00 AM GMT-0600'), current_value: 1}
    ]
});

【问题讨论】:

    标签: javascript oop extjs sencha-touch


    【解决方案1】:

    哦,伙计 - 我不知道我是如何偶然发现这个答案的,一个非常模糊的错字是唯一阻止它工作的东西。

    Ext.List() 使用它的itemSelector 属性来确定符合“点击”条件的元素。我的itemSelector 设置为.sets-list-item,但模板有<div class="set-list-item">。更正模板,itemtap 按预期触发。

    【讨论】:

      【解决方案2】:

      您可能需要查看updated screencast - 因为某些 API 在 1.0 版本中发生了更改,并且旧的截屏视频现在不同步了。

      【讨论】:

      • 从未看过截屏视频 - 感谢您提供链接!这是参考GeoTweets(不是我用来学习的GeoCongress),但无论如何我都会观看它以寻找线索。尽管如此,我引用的是有效的 1.0 API 文档,但没有任何突出之处。
      • 或者它现在已经脱离了“syncha”?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多