BackboneJS Rendering Problems

Partial rendering of views In order to minimize the full rendering of your DOM hierarchy, you can set up special nodes in your DOM that will reflect updates on a given property. Let’s use this simple Underscore template, a list of names: <ul> <% _(children).each(function(model) { %> <li> <span class=”model-<%= model.cid %>-name”><%= model.name %></span> : … Read more

Why is it considered bad practice to call trigger: true in the navigate function of backbone.js?

There seems to be some confusion about what Router#navigate does exactly, I think. Without any options set it will update the URL to the fragment provided. E.g. router.navigate(‘todo/4/edit’) will update the URL to #todo/4 AND will create a browser history entry for that URL. No route handlers are run. However, setting trigger:true will update the … Read more

Best practice for saving an entire collection?

Usually REST backends handle single instance creation/update. You would need to change that to accept an array of objects. That said, on the client side, you would need to go directly to the Backbone.sync function Backbone.sync = function(method, model, options) In this case your model should be an array of model. The method should be … Read more

Backbone.js history ‘on route change’ event?

There is the “route” event on the Router: http://backbonejs.org/#Events-catalog “route” (router, route, params) — Fired by history (or router) when any route has been matched. This allows you to bind to specific routes. If you want to fire a handler after any route, bind to “route”, and the route will be the first argument: myRouter.on(“route”, … Read more