Stating the obvious: 1) Try to use hash tagging and history to connect disparate views as much: you keep them independent from each other this way, and back button compatible. In other words: don’t spawn views programmatically, let the router do the work for you. 2) As much as you can: one view = one template […]
Category Archives: backbone.js
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 […]