-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path计数器.js
122 lines (121 loc) · 3.42 KB
/
计数器.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const DeviceSIZE = $device.info.screen
$ui.render({
props: {
title: "计数器",
navButtons:[
{
title: "addNew",
handler: function(){
var itemIndex = $("list").data.length;
$("list").insert({
index: $indexPath(itemIndex),
value: {
label: {
info: {
indexPath: itemIndex,
}
},
input: {
info: {
indexPath: itemIndex,
}
},
stepper: {
info: {
indexPath: itemIndex,
}
},
}
});
}
}
]
},
views: [
{
type: "list",
props: {
id: "list",
template: [
{
type: "view",
props: {
id: "itemView",
bgcolor: $rgba(177, 159, 132, 0.1),
radius: 5
},
layout: function (make, view) {
make.left.right.inset(10)
make.top.inset(5)
make.width.equalTo(DeviceSIZE.width - 40)
make.height.equalTo(40)
}
},
{
type: "input",
props:{
id: "input",
},
events:{
returned: function(sender){
var listData = $("list").data;
var myIndex = $("list").data.length - sender.info.indexPath - 1;
listData[myIndex].input.text = sender.text;
$("list").data = listData;
sender.blur();
$cache.set("listData", listData);
}
},
layout: function(make,view){
make.left.equalTo($("itemView"))
make.size.equalTo($size(170,40))
make.top.equalTo(view.supper).offset(5)
}
},
{
type: "label",
props:{
align: $align.center,
id: "label",
},
layout: function(make,view){
make.size.equalTo($size(50,40))
make.left.equalTo($("input").right).offset(20)
make.top.equalTo(view.supper).offset(5)
},
},
{
type: "stepper",
props:{
max: 10000,
value: 0,
id: "stepper",
},
layout: function(make,view){
make.size.equalTo($size(110,40))
make.right.equalTo($("itemView").right).offset(10)
make.centerY.equalTo($("itemView")).offset(5)
},
events: {
changed: function(sender){
var listData = $("list").data;
//sender.prev.text = sender.value; 通过 prev 获取前一个 view
var myIndex = $("list").data.length - sender.info.indexPath - 1; //向数组添加新值时,是从列表头部添加,所以取值时要倒序
listData[myIndex].label.text = JSON.stringify(sender.value);
listData[myIndex].stepper.value = sender.value;
$("list").data = listData;
$cache.set("listData", listData);
}
}
}
],
},
layout: $layout.fill,
events:{
ready: function(sender){
$("list").data = $cache.get("listData");
}
}
}
],
});