<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<nav title="首页">
<listview id="platnumberList" backgroundColor="#F1F1F5" itemBackgroundPress="#F1F1F5" width="100%" height="100%" onItemClick="itemClick" dividerColor="#0974DB" dividerVisible="true" enablePullDown="true" enablePullUp="true" >
<template>
<div width="100%" height="55" layout="HBox" vAlign="middle" >
<img tag='icon' marginLeft="20" >
</img>
<input type="label" tag="carLic" class="emp-myLabel" marginLeft="20" height="55" />
</div>
</template>
</listview>
</body>
<script>
var dataSource = new Array();
var items = [{
"carLic":"沪12332",
"icon" :"/images/widgets/checkbox/checkbox_unChecked.png"
},{
"carLic":"沪12343",
"icon" :"/images/widgets/checkbox/checkbox_unChecked.png"
},{
"carLic":"沪13444",
"icon" :"/images/widgets/checkbox/checkbox_unChecked.png"
},{
"carLic":"沪12356",
"icon" :"/images/widgets/checkbox/checkbox_unChecked.png"
},{
"carLic":"沪00560",
"icon" :"/images/widgets/checkbox/checkbox_unChecked.png"
}];
platnumberList.setItems(items);
platnumberList.reloadData()
function itemClick(row,tag,data)
{
var temp = {};
for(var a in data){
temp[a] =data[a];
}
if(data.icon == "/images/widgets/checkbox/checkbox_unChecked.png"){
temp.icon = "/images/widgets/checkbox/checkbox_checked.png";
var flag = checkHasData(temp.carLic);
if(flag == false)
{
dataSource.push(temp.carLic);
}
log("dataSource=="+dataSource)
}else{
temp.icon = "/images/widgets/checkbox/checkbox_unChecked.png";
var flag = checkHasData(temp.carLic);
if(flag >=0)
{
dataSource.splice(flag, 1);
}
}
platnumberList.updateItem(row, temp);
platnumberList.reloadData();
}
//检查是否含有数据
function checkHasData(carLic){
for(var i = 0; i < dataSource.length; i ++)
{
if(dataSource[i] == carLic)
{
return i;
}
}
return false;
}
</script>
</html>
Listview的多选demo示例代码
最新推荐文章于 2017-05-29 15:50:56 发布