UIActionSelector 是一个支持弹出动画的多级选择器。调用 open 接口,会从当前 window 底部弹出一个 action 选择器(记录用户上次的选择)
- https://docs.apicloud.com/Client-API/UI-Layout/UIActionSelector
UIActionSelector
- 默认元素可以ajax默认第一个值给元素赋值用户操作模块在用模块赋值
- actives是打开选择器默认选择元素
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74var one ;
var activess = [];
//打开UIActionSelector
function select_(){
UIActionSelector.open({
datas: [ //JSON 数组类型;第一级选择项数组
{
"id": "0",
"name": "北京市", //字符串类型;第一级选择项的名称
}, {
"id": "1",
"name": "河南省", //字符串类型;第一级选择项的名称
}, {
"id": "2",
"name": "哈尔滨", //字符串类型;第一级选择项的名称
}
],
layout: {
row: 5,
col: 1,
height: 30,
size: 12,
sizeActive: 14,
rowSpacing: 5,
colSpacing: 10,
maskBg: 'rgba(0,0,0,0.2)',
bg: '#fff',
color: '#888',
colorActive: '#f00',
colorSelected: '#f00'
},
animation: true,
actives: activess,
cancel: {
text: '取消',
size: 12,
w: 90,
h: 35,
bg: '#fff',
bgActive: '#ccc',
color: '#888',
colorActive: '#fff'
},
ok: {
text: '确定',
size: 12,
w: 90,
h: 35,
bg: '#fff',
bgActive: '#ccc',
color: '#888',
colorActive: '#fff'
},
title: {
text: '请选择',
size: 12,
h: 44,
bg: '#eee',
color: '#888'
},
fixedOn: api.frameName
}, function(ret, err) {
if (ret) {
var area = $api.byId('area');
if (ret.eventType == "ok") {
$api.setStorage('setActive', ret.selectedInfo)
fngetActive();
one = ret.selectedInfo[0].id ;
activess = [one];//在次点击默认选择的数据
}
}
});
}给ui设置默认值 setActive
- 设置默认值得获取的时候需要先打开(open)UIActionSelector否则只能找到level3:’’
- 而我现在的数据格式只有level1并且需要level1的值 官方默认会找到3级(level1、level2、level3)
1
2
3
4
5
6
7//设置UIActionSelector默认值
function fnsetActive() {
var UIActionSelector = api.require('UIActionSelector');
UIActionSelector.setActive({
actives: [0] //[0,0,0]
});
}获取UIActionSelector值 getActive
- 获取setActive默认设置的值将值传给元素然后将获取UIActionSelector值在隐藏达到设置默认值效果
1
2
3
4
5
6
7
8
9function fngetActive() {
UIActionSelector.getActive(function(ret, err) {
if (ret) {
var area = $api.byId('area');
area.innerHTML = ret.level1
}
});
}UIActionSelector隐藏 hide
1
2
3
4function fnhide() {
var UIActionSelector = api.require('UIActionSelector');
UIActionSelector.hide();
}