我这里有这个代码:
$.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的值。
我该怎么做?我想遍历此列表视图,只抓取列表视图中的选定项目。
谢谢, 肯尼
答案 0 :(得分: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);