滚动选择(Picker)
功能说明
该控件用于用户可以自定义选择的内容,并选择结果。
HTML5
<picker id="picker0" showsSelectionIndicator="true" ><pickeritem onselectedchange="noChange()" bindfield="no" value="编号" datasource="nos"/><pickeritem onselectedchange="nameChange()" bindfield="name" value="姓名" datasource="names"/><pickeritem onselectedchange="ageChange()" bindfield="age" value="年龄" datasource="ages"/></picker>
属性列表
| 属性名 | 属性值 | 说明 | 
|---|---|---|
| value | 当前picker项的值 | |
| bindfield | 控件绑定字段 | |
| showsselectionindicator | true/false | 是否显示选中框器 | 
| datasource | 类型为JSON对象,是每一个PickerItem的数据源,即滚轴内的可选数据 | |
| iscyclic | true/false | 是否支持循环滚动,使用方法见示例2 | 
| bindfield | 控件绑定字段 | 
支持公共属性
参见公共属性说明
事件列表
| 事件名 | 说明 | 
|---|---|
| onload | Picker加载时触发的事件 | 
| onselectedchange | 用户滚动puckerItem后,焦点离开即触发 | 
支持公共事件
参见公共事件说明
实例:
1、onload以及onselectedchange事件的使用
<picker id="picker0" showsSelectionIndicator="true" ><pickeritem onselectedchange="noChange()" bindfield="no" value="编号" datasource="nos"/><pickeritem onselectedchange="nameChange()" bindfield="name" value="姓名" datasource="names"/><pickeritem onselectedchange="ageChange()" bindfield="age" value="年龄" datasource="ages"/></picker>
function pickerload() {var context = {nos : ["001", "002", "003", "004", "005"],names : ["墨晨", "紫萱", "皓然", "紫依", "温暖"],ages : ["18", "19", "20", "21", "22"]}$ctx.push(context); //数据绑定,将context的值与picker进行绑定}function noChange() {$alert("编号:" + $ctx.getString("no"));}function nameChange() {$alert("姓名:" + $ctx.getString("name"));}function ageChange() {$alert("年龄:" + $ctx.getString("age"));}
2、设置是否支持循环滚动 iscyclic=”false”
<picker id="picker0" showsSelectionIndicator="true" ><pickeritem iscyclic="false" onselectedchange="noChange()" bindfield="no" value="编号" datasource="nos"/><pickeritem iscyclic="false" onselectedchange="nameChange()" bindfield="name" value="姓名" datasource="names"/><pickeritem iscyclic="false" onselectedchange="ageChange()" bindfield="age" value="年龄" datasource="ages"/></picker>
文档更新时间: 2018-01-15 14:31