forked from RubyLouvre/avalon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.html
109 lines (104 loc) · 4.35 KB
/
test1.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
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
<!DOCTYPE html>
<html>
<head>
<title>avalon入门</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- <script src="avalon.$events.js" type="text/javascript"></script>-->
<script src="../avalon.js" type="text/javascript"></script>
<script src="../mobile/mobile.js" type="text/javascript"></script>
<script>
var first = 0;
var model = avalon.define("test", function(vm) {
vm.firstName = "司徒"
vm.lastName = "正美"
vm.fullName = {//一个包含set或get的对象会被当成PropertyDescriptor,
set: function(val) {//里面必须用this指向scope,不能使用scope
var array = (val || "").split(" ");
this.firstName = array[0] || "";
this.lastName = array[1] || "";
},
get: function() {
return this.firstName + " " + this.lastName;
}
}
vm.color = "red"
vm.toggle = true
vm.changeToggle = function() {
model.toggle = !model.toggle
}
vm.v = "111111111111"
vm.switchColor = function() {
model.color = model.color === "red" ? "blue" : "red"
}
vm.html = '<strong>正美</strong>'
vm.arr = ["aaa", 'bbb', "ccc", "ddd"]
vm.sort = function() {
vm.arr.reverse()
}
vm.selected = ["bbb", "ccc"]
vm.checkAllbool = false
vm.checkAll = function() {
if (!first) {
first++
return
}
if (this.checked) {
vm.selected = vm.arr
} else {
vm.selected.clear()
}
}
vm.checkOne = function() {
var bool = this.checked
if (!bool) {
vm.checkAllbool = false
} else {
vm.checkAllbool = vm.selected.size() === vm.arr.size()
}
}
})
setTimeout(function() {
avalon.log(model.hasOwnProperty("fullName"))
})
setTimeout(function() {
model.html = "<em>aaa</em>bbb<em>dddd</em>"
}, 1000)
setTimeout(function() {
model.html = "1111<em>aaa</em>bbb<em>dddd</em>222"
}, 1000)
</script>
<style>
.ms-class-test{
background:green;
width:300px;
height:100px;
}
.c-red{
background: red;
}
.c-blue{
background: blue;
}
</style>
</head>
<body>
<div ms-controller="test">
<input ms-attr-value="v" value="2222222222"/>{{v}}
<p>First name: <input ms-duplex="firstName" /></p>
<p>Last name: <input ms-duplex="lastName" /> {{lastName | html}}</p>
<p>Hello, <input ms-duplex="fullName"></p>
<div>这是显示的内容{{firstName +" | "+ lastName }} <span style="color:gray">lastName尝试输入<em>test</em>看看</span></div>
<ul>
<li><input type="checkbox" ms-duplex-radio="checkAllbool" data-duplex-changed="checkAll"/>全选<button ms-click="sort" type="button">sort</button></li>
<li ms-repeat="arr" ><input type="checkbox" ms-value="el" ms-duplex="selected" data-duplex-changed="checkOne"/>{{el}} <strong>{{$index}}</strong></li>
</ul>
<ol ms-each="arr">
<li>ms-each {{el}}</li>
</ol>
<div class="ms-class-test" ms-hover="c-{{color}}:toggle"> </div>
<div><button ms-click="switchColor"> 点我改变悬浮时的背景颜色</button>现在悬浮色为{{color}}</div>
<div><button ms-click="changeToggle"> 点我{{toggle? "禁止": "开启" }}悬浮变色</button></div>
<div>hello,{{html | html}}!</div>
</div>
</body>
</html>