2010-11-30 52 views
2

我非常關注GeoCongress.us App中的代碼,因爲這是我的第一個Sencha Touch應用程序,並且該應用程序的佈局功能背後的前提與我希望實現的類似。Sencha Touch:列表ItemTap事件觸發

雖然我有一個問題讓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} 
    ] 
}); 

回答

1

哦,男人 - 我不知道我是怎麼偶然發現這個答案的,一個非常隱晦的錯字是阻止它工作的唯一的東西。

Ext.List()使用它的itemSelector屬性來確定哪些元素符合「點擊」的條件。我的itemSelector設置爲.sets-list-item,但模板有<div class="set-list-item">。按照預期修正模板和itemtap

0

您可能需要查看updated screencast - 因爲1.0版本中的一些API已更改,而舊版本的屏幕截圖現在不同步。

+0

從來沒有看過屏幕錄像 - 感謝您的鏈接!這是參考GeoTweets(而不是GeoCongress,我正在使用它來學習),但無論如何我要去看它以尋找線索。儘管如此,我正在引用有效的1.0 API文檔,沒有什麼是突出的。 – 2010-11-30 01:37:24