我正在密切关注GeoCongress.us 应用程序中的代码,因为这是我的第一个 Sencha Touch 应用程序,并且该应用程序的布局功能背后的前提与我希望实现的类似。
我在获取 List 对象以响应itemtap
事件时遇到问题。我的意图是itemtap
在关卡中捕获事件SetsScreen
,触发我自己的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}
]
});