// js/modules/room.js // Module reference argument, assigned at the bottom (function (Room) { // Dependencies var Util = app.module("util"), Device = app.module("device"); // The basic person model Room.Model = Backbone.Model.extend({ defaults: { roomId: null, title: 'undefined', devices: Device.List } }); Room.List = Backbone.Collection.extend({ model: Room.Model }); Room.View = Backbone.View.extend({ initialize: function () { this.$el.attr('id', 'room' + this.model.get('roomId')).addClass('room'); this.template = Handlebars.compile(Util.getTemplate('room')); this.devices = new Device.List(this.model.get('devices')); }, render: function () { this.$el.html(this.template(this.model.toJSON())); _.each(this.devices.models, function (device) { this.renderDevice(device); }, this); return this; }, renderDevice: function (device) { var deviceView = new Device.View({ model: device }); this.$el.append(deviceView.render().el); } }); })(app.module("room"));