Take the 2-minute tour ×

I want to use backbone.js for controlling a very heavy data application.

On this fiddle ( http://jsfiddle.net/D87cg/2/ ), you can see one page of the application (please note there are a lot more of components like menus, secondary menus, other boxes with content, footer and so on).

There are several json objects which a web service return:

  • One has the information for both specs and owner details
  • One has the "Your Accounts" information, but not all of the data is displayed (although it's sent on the json object, other statistics for each game are sent as well as some other games)

My doubt is... can backbone.js allow to have several views and models per page? I ask because the Route seems to see each route as a state in the whole view, which is reflected in the URL, but what if I have several objects in one page which can change at different times?

Is there a way to accomplish this? I've looked at several backbone.js tutorials but they all seem to see one page as a view.

My other question is... how do I integrate the json response so that the fields are not fixed on the model? On another words, how do I make the model use the attributes that come in the json file without having to define them in the model?

Thanks in advance!!

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Understand that the point of routes is to create bookmarkable URLs. You can have as many views, models, and controllers splattered across your viewport as you like, and as long as you don't care that a specific collection of views-on-display is a bookmarkable item, the state of what is currently being displayed can be managed internally by a hierarchy of views, rather than a router.

(Or you could be clever and save the state of views to your server as a bookmarkable route, and fetch the "what is shown for route ROUTEID" before assembling the views, but that's fun and tricky and clever.)

So, yes, the Routes thing is a bit of a red herring for the kind of application you're discussing. Backbone can handle it just fine.

share|improve this answer
Oh, thank you very much! So... Do I ditch Routes altogether? Because actually backbone is not the standard MVC if it only has models and views... How do I change one view for another? As you see, there are several "modules". Should there be a different view per item (one for SPECS, one for OWNER DETAILS...), a global one that changes according to data or one per item and module (one for filled SPECS, one for empty SPECS, one for filled OWNER DETAILS, one for OWNER DETAILS with info missing...)? –  Óscar Aug 30 '11 at 18:48
Trying to be "pure MVC" is over the top. Consider that the actual "view" is your DOM objects (HTML and CSS) and the backbone View is actually your controller: it contains syntactic logic to change your model's semantic logic. It also regiments a "view" (and subviews). Separate yourself from the idea that views "must" render, and consider that the "render" function just creates and returns an element that a parent view then places somewhere useful. The parent view has responsibility for organization, the masonry of the page, and each subview shows something about a model. –  Elf Sternberg Aug 30 '11 at 21:59
All right, @Elf Sternberg , thank you very much, I'll use that "parent view" approach then. Thanks again! –  Óscar Aug 31 '11 at 16:53
add comment

Your Answer


