-
Notifications
You must be signed in to change notification settings - Fork 126
/
tuto5b.html
45 lines (42 loc) · 1023 Bytes
/
tuto5b.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
<html>
<head>
<title>PURE Unobtrusive Rendering Engine</title>
<script src="../libs/jquery.js"></script>
<script src="../libs/pure.js"></script>
</head>
<body>
<!-- HTML template -->
<ul>
<li></li>
</ul>
<script>
var data = {
legs:4,
animals:[
{name:'dog', legs:4},
{name:'cat', legs:4},
{name:'bird', legs:2},
{name:'mouse', legs:4}
]
};
//declaration of the actions PURE has to do
var directive = {
'li':{
'animal<-animals':{
'.':'animal.name'
},
//sort function like the ususal Array.sort
sort:function(a, b){
return a.name > b.name ? 1 : -1;
},
filter:function(a){
//if the returned value is false, the rendering will be skipped for this entry
return a.context.legs === a.item.legs;
}
}
};
// note the use of render instead of autoRender, and the 2nd argument
$('ul').render(data, directive);
</script>
</body>
</html>