I want to filter a Backbone collection based on one or more of it's model's properties. I've read around the problem and I've noticed that the most discussed solution is to simply use this.where({"applicationType": application});
to filter and then either return a new collection or list of models to be rendered.
In principle I have no problem with this but having tried to implement it I noticed one problem. If I'm following the backbone design pattern of only re-rendering views when their parent collection fires an event to say something's changed then I think I have two options.
1: I take the list of filtered objects/ new collection and overwrite the master collection.
2: I change the collection the view is currently listening to, to the new filtered list.
The problem I have is that I want this process to be non-destructive to the master collection that's been received from the server. I always want to be able to clear away my filters and get back to that.
The one way I think I can do it is as follows:
Instead of returning a new instance of the collection I'm thinking of simply adding a 'display' flag to models that should be displayed. Then I will always be attempting to 'render' the whole collection but only the models with the display flag will be displayed, hence not destroying the master collection.
Is this the best way to approach the problem or am I missing an easy solution?