Backbone.js: event aggregation and AMD

Great pattern to decouple your modules, and still have clean mechanism to communicate between them. 1) Create a generic “Notifier” module: define([ ‘underscore’, ‘backbone’ ], function(_, Backbone) { var notifier = _.extend({}, Backbone.Events); return notifier; }); 2) In the two + views or models that you want to connect, include the notifier via your AMD […]

Backbone.js: binding collection resets

this.collection.bind(‘reset’, this.render, this); This is run in a view, probably in the initialization function. When the collection gets data from backend, it resets. The last “this” indicates context (in this case, it means the render will happen in this view). Looping through collections: _(this.collection.models).each(function (result) { currentNode.append(new CatalogNodeTableView({model: result}).render().el); });   Templates: example of an […]