-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathview2.html
50 lines (36 loc) · 1.25 KB
/
view2.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
<html>
<head>
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<div id="content"></div>
<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({
initialize: function() {
this.render();
},
events: {
"click .save": "save"
},
render: function() {
$(this.el).append('<input id="firstName" type="text" value="' + this.model.get('firstName') + '" /><br/>');
$(this.el).append('<input id="lastName" type="text" value="' + this.model.get('lastName') + '" /><br/><br/>');
$(this.el).append('<button class="save">Save</button>');
},
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>