forked from fabiooshiro/backbone-handlebars-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample02.html
63 lines (60 loc) · 1.73 KB
/
sample02.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
<!DOCTYPE html>
<html>
<head>
<title>Sample 01</title>
<script type="text/javascript" src="dependencies/jquery-1.7.1.js"></script>
<script type="text/javascript" src="dependencies/underscore-1.3.1.js"></script>
<script type="text/javascript" src="dependencies/backbone.js"></script>
<script type="text/javascript" src="dependencies/handlebars-1.0.0.beta.6.js"></script>
<script type="text/javascript" src="handlebars-backbone.js"></script>
<script type="text/javascript">
$(function(){
var Person = Backbone.Model.extend({
defaults: {
name: 'Michelangelo',
bornYear: 1475,
diedYear: 1564,
aged: function(){
return this.diedYear - this.bornYear;
},
sculpture: {
name: 'Pietà'
}
}
})
Handlebars.registerHelper('aprox', function(val) {
return "~ " + val;
});
var PersonView = Backbone.View.extend({
initialize: function(){
_.bindAll(this, "render");
this.model.bind('change', this.render);
},
template: $("#template"),
render: function () {
this.handleView(this.model);
return this;
}
});
new PersonView({el: $("#person"), model: new Person()}).render();
});
</script>
</head>
<body>
<script id="template" type="text/x-handlebars-template">
<div><strong>{{name}}</strong></div>
<div>Born: <input name="bornYear" /></div>
<div>
Died:
<select name="diedYear" >
<option value="1563">1563</option>
<option value="1564">1564</option>
<option value="1565">1565</option>
</select>
</div>
<div>Aged: {{aprox aged}} (calculated)</div>
<div>Sculpture: {{sculpture.name}}</div>
</script>
<div id="person"></div>
</body>
</html>