javascript - CompositeView where children can come from multiple collections -
here need in nutshell.
i need show dropdown/combobox children can come many collections. these collections' models have text attribute show in dropdown.
i wondering if possible create dropdown's list many collections.
namely:
collection 1 has: text: a, fungus: 9 text: b, fungus: 7 text: c, fungus: 6 collection 2 has: text: q, numberofbugs: 8 text: r, numberofbugs: 9 text: s, numberofbugs: 7
the list dropdown ends looking like:
<option>a</option> <option>a</option> <option>a</option> <option>q</option> <option>r</option> <option>s</option>
so if select a, want able a's model fungus attribute, , if select r want r's model has numberofbugs attribute.
the idea 2 collections common attributes, in backend correspond different models.
is there way in marionette/backbone?
some way create dropdown has multiple data sources / collections?
merging 1 collection not work because sync / fetch operations not work correctly.
if collection work in application, make them single collection start , use subcollections using backbone-filtered-collection custom behaviors , sync / fetch: models added subcollection added general one.
var general = new backbone.collection var fungus = new filteredcollection(general) var bugs = new filteredcollection(general) fungus.filterby(function(model){ return model.has('fungus') }) bugs.filterby(function(model){ return model.has('numberofbugs') }) general.add([ {text: 'a', fungus: 9}, {text: 'b', fungus: 7}, {text: 'c', fungus: 6}, {text: 'q', numberofbugs: 8}, {text: 'r', numberofbugs: 9}, {text: 's', numberofbugs: 7} ]) // general.length => 6 // fungus.length => 3 // bugs.length => 3
hope helps
Comments
Post a Comment