forked from ruanyf/jstraining
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
45 lines (34 loc) · 866 Bytes
/
main.js
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
(function() {
window.App = {
Models: {},
Collections: {},
Views: {},
Router: {}
};
App.Router = Backbone.Router.extend({
routes: {
'': 'index',
'show/:id': 'show',
'download/*random': 'download',
'search/:query': 'search',
'*other': 'default'
},
index: function() {
$(document.body).append("调用了 Index 路由<br>");
},
show: function(id) {
$(document.body).append("调用了 Show 路由,id 等于 " + id + "<br>");
},
download: function(random) {
$(document.body).append("调用了 Download 路由,参数等于 " + random + "<br>");
},
search: function(query) {
$(document.body).append("调用了 Search 路由,参数等于 " + query + "<br>");
},
default: function(other) {
$(document.body).append("你访问的 " + other + " 路由未定义<br>");
}
});
new App.Router();
Backbone.history.start();
})();