-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
84 lines (72 loc) · 1.98 KB
/
index.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" href="http://twitter.github.io/bootstrap/1.4.0/bootstrap.min.css" />
</head>
<body>
<div class="container">
<h1>User Manager</h1>
<hr />
<div class="page"></div>
</div>
<script type="text/template" id="user_id_template">
<table class="table striped">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th></th>
</thead>
<tbody>
<% _.each(users, function(user){%>
<tr>
<td><%=user.get('firstname')%></td>
<td><%=user.get('lastname')%></td>
<td><%=user.get('age')%></td>
<td></td>
</tr>
<% });%>
<tbody>
</table>
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script>
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
options.url = "http://backbonejs-beginner.herokuapp.com" + options.url;
});
var Users = Backbone.Collection.extend({
url: "/users"
});
var UserList = Backbone.View.extend({
el : '.page',
render : function(){
var that = this;
var users = new Users();
users.fetch({
success: function(users){
var template = _.template($('#user_id_template').html(), {users: users.models});
console.log(users.models);
that.$el.html(template);
}
});
}
});
var Router = Backbone.Router.extend({
routes : {
'': 'home' //
}
});
var userList = new UserList();
var route = new Router();
route.on('route:home', function(){
userList.render();
console.log("we have load homepage");
});
Backbone.history.start();
</script>
</body>
</html>