我正在密切关注 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}
]
});
最佳答案
天哪 - 我不知道我是怎么偶然发现这个答案的,一个非常模糊的错字是唯一阻止它工作的东西。
Ext.List()
使用它的 itemSelector
属性来确定什么元素符合“点击”的条件。我的itemSelector
被设置为 .sets-list-item
但是模板有 <div class="set-list-item">
.更正模板和itemtap
正在按预期开火。
关于javascript - Sencha 触摸 : List ItemTap Event Firing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4309744/