Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>init: function(){ this.initial = new Init(); this.initialView = new InitView({model: this.initial}); this.initial.fetch(); } </code></pre> <p>looks as I'd expected, but this:</p> <pre><code>clefs = new CustomCollection(); clefs.add(response.clefs); this.set({clefs: clefs}); </code></pre> <p>Not so much. I'm a bit of a Backbone.js newb myself, so I'm still learning the best way to deal with composite models as well. What I've done previously is have a view keep track of two models (as it showed a list of lists, but with only one of the sublists viewable at any given time). Whenever an item of the first list was clicked, the model containing the sublist was selected, and from that model would "get" the field, toJSON() it (which is a really unfortunate name because it's not a JSON string but the object representation), and then reset a model bound to a view for the current sublist to be displayed. That's a bit hard to explain without code but I'm a little short on time at the moment. Later I may try to explain better (maybe with another answer).</p> <p><strong>EDIT 1</strong></p> <p>Just to clarify, my objection was to assigning through <code>set</code> and later retrieving through <code>get</code>. I'm just not sure how Backbone.js would handle that. I'd love to know, though.</p> <p><strong>EDIT 2</strong></p> <p>You might want to look at: <a href="https://stackoverflow.com/questions/6353607/backbone-js-structuring-nested-views-and-models/#answer-6476507">backbone.js structuring nested views and models</a></p> <p>Basically, he suggests instead of assigning through set, you just make the sub models properties of the composite model</p> <p>so instead of </p> <pre><code>parse: function(response) { clefs = new CustomCollection(); clefs.add(response.clefs); this.set({clefs: clefs}); ..... </code></pre> <p>You'd have</p> <pre><code>parse: function(response) { this.clefs = new CustomCollection(); this.clefs.add(response.clefs); /*Or maybe you really mean this.clefs.reset(response.clefs)*/ ..... /* something similar for rests, etc */ } </code></pre> <p>And then if you wanted to bind a specific view, in your Router, assuming you've defined CleftsView, RestsView, etc.</p> <pre><code> init: function(){ this.initial = new Init(); this.initialView = new InitView({model: this.initial}); this.clefsView = new ClefsView({model: this.initial.clefs}); this.restsView = new RestsView({model: this.initial.rests}); ..... this.initial.fetch(); ..... } </code></pre> <p>I might have suggested this earlier, but I wasn't sure if this was a common practice or not. I'mt still not sure if I like the suggestion, as I'd be tempted to put the rests and clefts models under a "models" property of <code>Init</code> instead of directly under <code>Init</code>. </p>
 

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