-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathview3.html
56 lines (40 loc) · 1.31 KB
/
view3.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
<html>
<head>
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<div id="content"></div>
<script type="text/template" id="employee-tpl">
<input id="firstName" type="text" value="<%= firstName %>" /><br/>
<input id="lastName" type="text" value="<%= lastName %>" /><br/><br/>
<button class="save">Save</button>
</script>
<script type="text/javascript" src="lib/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="lib/underscore-min.js"></script>
<script type="text/javascript" src="lib/backbone-min.js"></script>
<script type="text/javascript">
Employee = Backbone.Model.extend({
urlRoot: "api/employees"
});
EmployeeView = Backbone.View.extend({
template: _.template($('#employee-tpl').html()),
initialize: function() {
this.render();
},
events: {
"click .save": "save"
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
},
save: function() {
this.model.save({firstName: $('#firstName').val(), lastName: $('#lastName').val()});
}
});
employee = new Employee({id: 1});
employee.fetch({success: function() {
new EmployeeView({model: employee, el: '#content'});
}});
</script>
</body>
</html>