0

我在应用加速器 Titanium 中有疑问:如何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);
4

1 回答 1

0

如果您想获得 Section Index ,希望对您有所帮助:

listView.addEventListener('itemclick', function(e) {

    alert("SectionID" + data.sessions[e.sectionIndex].Session_Name);
});
于 2014-05-27T08:11:05.873 回答