-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshell.html
91 lines (90 loc) · 2.8 KB
/
shell.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!doctype html>
<head>
<title>Backbone Sandbox</title>
</head>
<body>
<h1>Let the fun begin!</h1>
<div id="app" class="container-fluid"></div>
<script src="app/components/requirejs/require.js"></script>
<script type="text/javascript">
require.config({
paths: {
jquery: 'app/components/jquery/jquery',
underscore: 'app/components/underscore-amd/underscore',
backbone: 'app/components/backbone-amd/backbone',
backboneLocalStorage: 'app/components/backbone.localStorage/backbone.localStorage'
},
shim: {
bootstrap: {
deps: ['jquery'],
exports: 'jquery'
}
}
});
require(['jquery', 'underscore', 'backbone'],
function($, _, Backbone) {
var Book = Backbone.Model.extend({});
var Books = Backbone.Collection.extend({
model: Book
});
var Library = Backbone.Model.extend({
initialize: function(options) {
var self = this;
this.books = options.books ? options.books : [];
this.books.url = function() {
return self.url() + '/books';
};
urlRoot: '/library/'
}
});
var books = new Books([
{
id: 1,
title: "The Lord of the Rings",
author: "J. R. R. Tolkien",
categories: ['fiction', 'adventure']
},
{
id: 2,
title: "The Hobbit",
author: "J. R. R. Tolkien",
categories: ['fiction', 'adventure']
},
{
id: 3,
title: "The Lion, the Witch, and the Wardrobe",
author: "C. S. Lewis",
categories: ['fiction', 'adventure']
},
{
id: 4,
title: "The 7 Habits of Highly Effective People",
author: "Stephen R. Covey",
categories: ['self-help']
},
{
id: 5,
title: "Who Moved My Cheese?",
author: "Spencer Johnson",
categories: ['self-help']
}
]);
var library = new Library({books: books, title: "Little Town's Library"});
console.log("Library: ");
console.log(library.get('title'));
console.log('');
library.get('books').each(function(b) {
console.log(b.get('title'));
console.log(b.get('author'));
console.log("Categories: ");
_.each(b.get('categories'), function(c) {
console.log(' '+c);
});
console.log('');
});
});
</script>
</body>
</html>
</body>
</html>