3 ms·
I'd like to see something like this for Backbone collections, e.g. it would take a query on model attributes and generate a subset of the original collection. T
by rgarcia 15y ago
I'd like to see something like this for Backbone collections, e.g. it would take a query on model attributes and generate a subset of the original collection. Then any views (not just lists) tied to this subset would update automatically.
In fact I think with _.fiter() you could probably do this in a few lines.
- jashkenas 15y agoVoila. collection.each(function(model) { model.set({visible: matchesSearch(model)}); }); And then, in your view: model.bind("change:visible", function() { $(this.el).toggle(model.get("visible")); }); ... assuming that you have a "matchesSearch" function that can tell you if a given model matches the current search term.
- crescentfresh 15y agoI've tweaked the proposal at http://stackoverflow.com/questions/6865174/backbone-js-correct-way-of-filter-collection-data-and-display-in-view/6865316#6865316 http://stackoverflow.com/questions/6865174/backbone-js-corre... to do just what you describe.
- rudasn 15y agodon't want to hijack the thread, but perhaps something like this http://rudasn.github.com/meelo-store http://rudasn.github.com/meelo-store ?