簡體   English   中英

鈦事件監聽器,用於ListSection的數組

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM