I have a page that creates a table using backbone.js. each table row is a backbone view. These views all have a model, and these model are in a backbone collection. Basic stuff.
Let’s say I want to search trough this table, which has about 800 rows. I have two options here.
- I can use one of the jQuery plugins that will search the complete table, and will hide the rows that do not match my search criteria. That works fine, pretty basic.
But since I am using backbone to create the page, I was thinking of a new approach.
- I can just destroy the table that’s on the page right now.
findthe elements in the collection, and just creates those views.
Method 1 alters DOM elements, and searches trough the DOM.
Method 2 destroys and creates DOM elements (and backbone views), and searches trough JS Objects (backbone models).
—
Question: Which one do you you prefer and why?
In general, I’d say search through the Backbone collection. If you’re using Backbone, you get all the functionality of Underscore for free, so use it, not jQuery to perform searches on your data. It’s not clear from what you’ve said so far, exactly what you’re trying to do, so you’ll need to be more specific about that if you want a more concrete example of what to do.