Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 1 | var ContactManager = new Marionette.Application(); |
| 2 | |
| 3 | ContactManager.addRegions({ |
| 4 | mainRegion: "#main-region" |
| 5 | }); |
| 6 | |
| 7 | ContactManager.Contact = Backbone.Model.extend({}); |
| 8 | |
| 9 | ContactManager.ContactCollection = Backbone.Collection.extend({ |
| 10 | model: ContactManager.Contact |
| 11 | }); |
| 12 | |
| 13 | ContactManager.ContactItemView = Marionette.ItemView.extend({ |
| 14 | tagName: "li", |
| 15 | template: "#contact-list-item" |
| 16 | }); |
| 17 | |
| 18 | ContactManager.ContactsView = Marionette.CollectionView.extend({ |
| 19 | tagName: "ul", |
| 20 | childView: ContactManager.ContactItemView |
| 21 | }); |
| 22 | |
| 23 | ContactManager.on("start", function(){ |
| 24 | var contacts = new ContactManager.ContactCollection([ |
| 25 | { |
| 26 | firstName: "Bob", |
| 27 | lastName: "Brigham", |
| 28 | phoneNumber: "555-0163" |
| 29 | }, |
| 30 | { |
| 31 | firstName: "Alice", |
| 32 | lastName: "Arten", |
| 33 | phoneNumber: "555-0184" |
| 34 | }, |
| 35 | { |
| 36 | firstName: "Charlie", |
| 37 | lastName: "Campbell", |
| 38 | phoneNumber: "555-0129" |
| 39 | } |
| 40 | ]); |
| 41 | |
| 42 | var contactsView = new ContactManager.ContactsView({ |
| 43 | collection: contacts |
| 44 | }); |
| 45 | |
| 46 | ContactManager.mainRegion.show(contactsView); |
| 47 | }); |
| 48 | |
| 49 | ContactManager.start(); |