2014-03-24 22 views
0

我有這樣的代碼在這裏:在ListView標記的項目,然後通過他們循環搶選中的項目性質

$.clientList.addEventListener('itemclick', function(e){ 
    var item = e.section.getItemAt(e.itemIndex); 
    var items = e.section.getItems(); 

    if (item.properties.accessoryType == Ti.UI.LIST_ACCESSORY_TYPE_NONE) { 
     item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK; 
    } 
    else { 
     item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_NONE; 
    } 
    e.section.updateItemAt(e.itemIndex, item); 

}); 

,讓我來檢查並取消項目在我的列表視圖。我想在用戶完成檢查這個listview中的項目之後。從列表視圖中獲取item.properties.clientname和item.properties.clientid的值。

我該怎麼做?我想通過這個listview循環,只抓取listview的選定項目。

感謝, 肯尼

+0

http://developer.appcelerator.com/question/163878/loop-through-listview-to-grab-items-with-certain-properties#comment-206400 –

回答

2
function convertListToArrayOfClients(list) { 
    var sections = list.sections, 
     retVal = []; 
    for(var i = 0, iL = sections.length; i < iL; i++) { 
     var section = sections[i], 
      items = section.items; 
     for(var j = 0, jL = items.length; j < jL; j++) { 
      var item = items[j]; 
      retVal.push({ 
       clientid: item.properties.clientid, 
       clientname: item.properties.clientname, 
       checked: item.properties.accessoryType == Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK 
      }); 
     } 
    } 
    return retVal; 
} 
var arr = convertListToArrayOfClients($.clientList); 
相關問題