-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (37 loc) · 1.15 KB
/
app.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
import Backbone from 'backbone';
import _ from 'underscore';
import $ from 'jquery';
import ItemView from './views/ItemView';
import Items from './collections/Items';
// Initialize the app router
var AppRouter = Backbone.Router.extend({
routes: {
'': 'showList',
},
initialize: function () {
this.items = new Items([
{ name: 'Item 1', done: false },
{ name: 'Item 2', done: true },
]);
},
showList: function () {
// Define a custom list view
var ListView = Backbone.View.extend({
el: '#item-list',
render: function () {
this.$el.empty(); // Clear the element
this.collection.each(function (item) {
var itemView = new ItemView({ model: item });
this.$el.append(itemView.render().el);
}, this);
return this;
},
});
var listView = new ListView({
collection: this.items,
});
listView.render();
},
});
var appRouter = new AppRouter();
Backbone.history.start();