-
Notifications
You must be signed in to change notification settings - Fork 3
/
router2.html
63 lines (48 loc) · 1.86 KB
/
router2.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
<html>
<head>
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<div id="content">
<ul class="list"></ul>
<div class="summary"></div>
</div>
<script type="text/template" id="employee-tpl">
<p><label>Id:</label><input type="text" id="id" value="<%= id %>" disabled /></p>
<p><label>First Name:</label><input type="text" id="firstName" value="<%= firstName %>" /></p>
<p><label>Last Name:</label><input type="text" id="lastName" value="<%= lastName %>" /></p>
<p><label>Title:</label><input type="text" id="title" value="<%= title %>" /></p>
<button class="save">Save</button>
</script>
<script type="text/template" id="employee-list-item-tpl">
<a href="#employees/<%= id %>"><%= firstName %> <%= lastName %></a>
</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" src="js/employee-model.js"></script>
<script type="text/javascript" src="js/employee-collection.js"></script>
<script type="text/javascript" src="js/employee-view.js"></script>
<script type="text/javascript" src="js/employee-list-view.js"></script>
<script type="text/javascript">
Router = Backbone.Router.extend({
routes: {
"" : "list",
"employees/:id" : "summary"
},
list: function() {
this.list = new EmployeeCollection();
var view = new EmployeeListView({model: this.list, el: ".list"});
this.list.fetch();
},
summary: function(id) {
if (this.currentView) this.currentView.undelegateEvents();
var employee = this.list.get(id);
this.currentView = new EmployeeView({model: employee, el: '.summary'});
}
});
app = new Router();
Backbone.history.start();
</script>
</body>
</html>