Non-destructive filtration of the collective grid

I want to filter a Backbone collection based on one or more of its model properties. I read this problem and I noticed that the most discussed solution is to just use this.where({"applicationType": application});

to filter and then either return a new collection or a list of models to be displayed.

Basically I have no problem with this, but while trying to implement it I noticed one problem. If I follow the design pattern of base objects only for re-rendered views when their parent collection fires an event to change something, I think I have two options.

1: I take a list of filtered objects / new collection and overwrite the main collection.

2: I change the collection that the view is currently listening to with a new filtered list.

The problem is that I want this process to be non-destructive to the main collection retrieved from the server. I always want to clear my filters and come back to this.

In one case, I can do it like this:

Instead of returning a new instance of the collection, I am thinking of simply adding the "display" flag to the models that should be displayed. Then I will always try to "display" the entire collection, but only models with a display flag will be displayed, hence not destroying the master collection.

Is this the best way to approach the problem, or am I missing a simple solution?

+3


source to share


1 answer


It sounds like you want to display specific models in the collection based on state, but still keep the collection intact. If it's just a rendering issue, this is ideal for Virtual Collections .



+2


source







All Articles