[英]Titanium eventslistener for an array of ListSection
我在鈦合金appcelerator中有疑問:如何動態概括EventListener
? 在我的項目中,我有一個動態創建的listSection
數組。 問題是,如何創建事件偵聽器,以允許整個listView
共享事件的相同行為?
var sections = [];
var SectionOne = Ti.UI.createListSection({
headerTitle : "Section one"
});
var SectionTwo = Ti.UI.createListSection({
headerTitle : "Section two"
});
var SectionThree = Ti.UI.createListSection({
headerTitle : "Section three"
});
sections.push(SectionOne);
sections.push(SectionTwo);
sections.push(SectionThree);
/*problem below*/
listView.addEventListener('itemclick', function(e) {
for (var sec in sections) {
var item = sections[sec].getItemAt(e.itemIndex);
if (item.properties.accessoryType == Ti.UI.LIST_ACCESSORY_TYPE_NONE) {
audioPlayer.start();
item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK;
item.properties.color = 'red';
Ti.API.info('e.index: ' + e.itemIndex);
} else {
audioPlayer.stop();
item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_NONE;
item.properties.color = 'black';
}
sections[sec].updateItemAt(e.itemIndex, item);
}
});
win.add(listView);
我希望它對您有所幫助:
listView.addEventListener('itemclick', function(e) {
alert("SectionID" + data.sessions[e.sectionIndex].Session_Name);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.