-
Notifications
You must be signed in to change notification settings - Fork 42
/
templates-and-datalink.html
85 lines (71 loc) · 2.04 KB
/
templates-and-datalink.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script src="jquery.datalink2.js" type="text/javascript"></script>
<script src="jquery.tmpl2.js" type="text/javascript"></script>
</head>
<body>
<button onclick="showData()">show data</button>
<script id="showData" type="text/x-jquery-tmpl">
<div>${firstName} ${lastName}</div>
</script>
<button onclick="setName( 1 )">set name</button>
<button onclick="insertItem()">insertItem</button>
<hr />
<h4>People Grid</h4>
<table>
<tbody id="peopleGrid"></tbody>
</table>
<hr />
<b>Console</b>
<div id="console"></div>
<script id="myTmpl" type="text/x-jquery-tmpl">
<tr>
<td colspan="2">
Name: <span data-jq-bind="firstName">${firstName}</span>
<span data-jq-bind="lastName">${lastName}</span>
</td>
</tr>
<tr>
<td><input data-jq-link="firstName" data-jq-bind="firstName" value="${firstName}" /></td>
<td><input data-jq-link="lastName" data-jq-bind="lastName" value="${lastName}" /></td>
</tr>
</script>
<script type="text/javascript">
function render() {
$("#nameTmpl").tmpl( person ).appendTo("#result");
}
var people = [
{
firstName: "Jo",
lastName: "Proctor"
},
{
firstName: "Elspeth",
lastName: "Jones"
}
];
$( "#peopleGrid" ).html(
$( "#myTmpl" ).tmplToString( people, { annotate: true })
);
$( "#peopleGrid" ).tmplActivate( "#myTmpl", people );
function setName( i ) {
$.setField( people[ i ], "firstName", "changedFirst" );
$.setField( people[ i ], "lastName", "changedLast" );
}
function insertItem() {
$.changeArray( people, "push", {
firstName: "newFirst",
lastName: "newLast"
});
}
</script>
<script type="text/javascript">
function showData() {
$( "#console" ).append("-----------------");
$( "#showData" ).tmpl( people ).appendTo( "#console" );
}
</script>
</body>
</html>