forked from thecountofzero/canjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
91 lines (88 loc) · 2.25 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>can.view.ejs demo</title>
<link rel="stylesheet" type="text/css" href="../../util/demos/demos.css" />
</head>
<body>
<table id='layout'>
<tr>
<td colspan="2"><h2>template</h2></td>
</tr>
<tr>
<td>
<textarea id='teacherEjs'><h2 class='<%= teacher.attr('grade')
< 'c'? "good" : "bad" %>'>
<%= teacher.attr('name') %>
</h2>
<ul>
<% list(teacher.students,
function(student){ %>
<li>
<%= student.attr('name') %>
</li>
<% }) %>
</ul></textarea>
</td>
<td class="explanation">The template shown is rendered with the data below. You can change it and click <button id='reapply'>Reapply</button>
to see the result change. Can.view renders the template with the data and appends it to the element as shown. If data is changed,
the results automatically update with live binding</td>
</tr>
<tr>
<td colspan="2"><h2>data</h2></td>
</tr>
<tr>
<td>
<div id='ejs-data-container'>
<pre id='ejs-data'></pre>
</div>
</td>
<td class="explanation">Change the data's properties by hovering over any of them. Without even reapplying the template, the result below
will update (because of live binding).</td>
</tr>
<tr>
<td colspan="2"><h2>can.view( template, data )</h2></td>
</tr>
<tr>
<td colspan="2"><div id='teacher'></div></td>
</tr>
</table>
</div>
<script type='text/javascript' src='../../../steal/steal.js'></script>
<script type='text/javascript'>
steal('can/view/ejs',
'can/util/json.js',
'can/observe',
'can/util/demos/observer.js',
function() {
var teacher = new can.Observe({
name : "Mr. Smith",
grade : "a",
students : [
{name : "Brian"},
{name : "Payal"},
{name : "Curtis"},
{name : "Alexis"}
]
});
new Observer( $("#ejs-data"),
{
observe : teacher,
fullName : "new can.Observe("
});
var reapply = function(){
$("#reapply").removeClass("glow");
var viewText = document.getElementById("teacherEjs").value,
result = new can.EJS({text: viewText}).render({teacher: teacher}),
frag = can.view.frag(result);
$('#teacher').html( frag );
}
$('#reapply').bind("click", reapply);
$('#teacherEjs').bind("keypress", function(){
$("#reapply").addClass("glow");
});
reapply();
})
</script>
</body>
</html>