Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From my experience, Backbone gives you finer-grained control over how you want to display your views: you should be able to replace only parts of your view without having to choose between "replace everything" and "append to the current HTML".</p> <p>It's generally a good idea to break up your views in several HTML files (especially given that you can use templating, e.g. with Underscore), but I don't think you should load everything at once if that's what you mean.</p> <p>I'll give you a more detailed example if you feel that it would answer to your question, but basically if you press a link or a button you're able to catch that event and do whatever you want with it, from replacing the whole view to just changing one single element.</p> <p>EDIT: I'll answer the rest of your question here. First you should have a look at <a href="http://backboneboilerplate.com/" rel="nofollow">http://backboneboilerplate.com/</a>, it's a pretty good demonstration of how to structure a backbone application. In particular, they use a view manager (vm.js) which handles creating the views.</p> <p>Using something like this allows you to keep in memory the last instance of a view. For example, when you click on a news item you'd have your router navigating to /news/item/xx, and you'd use the view manager to create a news item and fill the model with localStorage (if you have already fetched the content) or by polling the server. Looking at the view manager code, you can have something like this:</p> <pre><code>define([ 'jquery', 'underscore', 'backbone', 'events' ], function($, _, Backbone, Events){ var views = {}; var create = function (context, name, View, options) { if(typeof views[name] !== 'undefined') { if (name === "homeview") { views[name].reinit(); // &lt;==== re-initialize your view return views[name]; } else { views[name].undelegateEvents(); if(typeof views[name].clean === 'function') { views[name].clean(); } } } var view = new View(options); views[name] = view; if(typeof context.children === 'undefined'){ context.children = {}; context.children[name] = view; } else { context.children[name] = view; } Events.trigger('viewCreated'); return view; }; return { create: create }; }); </code></pre> <p>That way, the view manager keeps your home view in memory, and re-initialize and returns it whenever you come back to it (I called .reinit() but it could be any custom function to reset your view to the state you previously saved and render it)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload