forked from doctyper/jquery-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
50 lines (40 loc) · 1.38 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
<script src="http://code.jquery.com/jquery.js"></script>
<script src="jquery.tmpl.js"></script>
<script>
jQuery(function(){
var dataObject = {
name: "John Resig",
url: "http://ejohn.org/",
cities: [
"Boston, MA",
"San Francisco, CA"
]
};
var arrayOfDataObjects = [ dataObject, dataObject, dataObject ];
var tmpl = '<li><%= $i %>) <a href="<%= url %>"><%= name %></a> (<%= cities.join(", ") %>)</li>';
$("#sometmpl")
.render( dataObject ) // Returns a LI with all the data filled in
.appendTo("ul");
$("#sometmpl")
.render( arrayOfDataObjects ) // Returns multiple LIs with data filled in
.appendTo("ul");
$("#sometmpl2")
.render( arrayOfDataObjects ) // Returns multiple LIs with data filled in
.appendTo("ul");
// Appends one LI, filled with data, into the UL
$("ul").append( tmpl, dataObject );
// Appends multiple LI, filled with data, into the UL
$("ul").append( tmpl, arrayOfDataObjects );
});
</script>
<script id="sometmpl" type="text/html">
<li><%= $i %>) <a href="<%= url %>"><%= name %></a>
(<%= cities.join(", ") %>)</li>
</script>
<script id="sometmpl2" type="text/html">
<li><%= $i %>) <a href="<%= url %>"><%= name %></a> Cities:
<% for ( var i = 0; i < cities.length; i++ ) {
text( cities[i] );
} %></li>
</script>
<ul></ul>