forked from RubyLouvre/avalon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepeat7.html
83 lines (79 loc) · 2.87 KB
/
repeat7.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>ms-repeat</title>
<script src="avalon.$events.js"></script>
<style>
ul{
display:inline-block;
float:left;
margin:20px;
width:300px;
height:300px;
border:1px solid #ccc;
list-style: none;
}
</style>
<script>
var model = avalon.define("test", function(vm) {
vm.left = [
{checked: false, text: "1111"},
{checked: false, text: "2222"},
{checked: false, text: "3333"},
{checked: false, text: "4444"},
{checked: false, text: "5555"}
]
vm.array3 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
vm.right = []
vm.addToRight = function() {
var array = []
model.left.forEach(function(el) {
if (el.checked) {
var model = avalon.mix({}, el.$model)
model.checked = false
array.push(model)
}
})
model.left.removeAll(function(el) {
return el.checked
})
model.right.push.apply(model.right, array)
}
vm.addToLeft = function() {
var array = []
model.right.forEach(function(el) {
if (el.checked) {
var model = avalon.mix({}, el.$model)
model.checked = false
array.push(model)
}
})
model.right.removeAll(function(el) {
return el.checked
})
model.left.push.apply(model.left, array)
}
})
</script>
</head>
<body ms-controller="test">
<h3>两个数组间的元素移动</h3>
<p><button type="button" ms-click="addToRight">--></button>
<button type="button" ms-click="addToLeft"><--</button>
</p>
<hr/>
<ul>
<li ms-repeat="left"><input ms-duplex-radio="el.checked" type="checkbox">{{el.text}}</li>
</ul>
<ul>
<li ms-repeat="right"><input ms-duplex-radio="el.checked" type="checkbox">{{el.text}}</li>
</ul>
<h3>$outer的使用</h3>
<table border="1">
<tr ms-repeat-el="array3">
<td ms-repeat-elem="el">{{elem}} 它位于第<b style="color:orchid">{{$outer.$index}}</b>行</td>
</tr>
</table>
</body>
</html>