/
06_data-binding2.html
78 lines (62 loc) · 1.96 KB
/
06_data-binding2.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
<!DOCTYPE html>
<html>
<head>
<link href="../resources/presentation.css" rel="stylesheet" type="text/css" />
<link href="../resources/syntaxhighlighter.css" rel="stylesheet" type="text/css" />
<script src="../resources/syntaxhighlighter.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
<script src="../../jsrender.js" type="text/javascript"></script>
<script src="../../jquery.observable.js" type="text/javascript"></script>
<script src="../../jquery.views.js" type="text/javascript"></script>
</head>
<body>
<div class="nav"><a href="06_data-binding.html">Prev</a> <a href="index.html">Index</a> <a href="07_observable.html">Next</a></div>
<h3>JsViews: Data binding - compact linking API syntax</h3>
<!--====== Container ======-->
<table><tbody id="details"></tbody></table>
<!--====== Template ======-->
<script id="personTmpl" type="text/x-jsrender">
<tr>
<td data-link="firstName"></td>
<td>
<input data-link="firstName trigger=true" />
</td>
</tr>
</script>
<!--====== Script ======-->
<script type="text/javascript">
var people = [
{
firstName: "Jeff"
},
{
firstName: "Rebecca"
}
];
// Compile template
$.templates( "personTmpl", "#personTmpl" );
// Render and link (compact syntax): data-link people to the
// details container, using the personTmpl template
$.link.personTmpl( "#details", people );
</script>
<!--================ End of Demo Section ================-->
<h4>HTML:</h4>
<pre class="brush: xml;">
<!-- Template, with declarative data binding expressions -->
...
<td data-link="firstName"></td>
<td>
<input data-link="firstName" />
</td>
...
</pre>
<h4>Script:</h4>
<pre class="brush: js;">
// Compile template
$.templates( "personTmpl", "#personTmpl" );
// Render and link (compact syntax): data-link people to the
// details container, using the personTmpl template
$.link.personTmpl( "#details", people );
</pre>
</body>
</html>