Titanium eventslistener用于ListSection数组

我在加速器Titanium中有问题:我如何动态概括EventListener?在我的项目中,我有一个动态创建的listSection数组。问题是,我如何创建一个事件监听器来允许整个listView共享相同的事件行为?Titanium eventslistener用于ListSection数组

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);

});

以上是 Titanium eventslistener用于ListSection数组 的全部内容, 来源链接: utcz.com/qa/265103.html

回到顶部