开发者

Several models and views per page with backbone.js

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 s开发者_StackOverflowent 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!!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜