Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone collection where clause with OR condition

I have searched for this for quite some time but could not get a way to have a where clause with or condition. For example if I have a collection Cars and I try to do the following:

Cars.where({
            model: 1998,
            color: 'Black',
            make: 'Honda' 
          })

So what the above will do is search for a car whose model is 1998 AND color is Black AND make is Honda.

But I require a way to get cars which have either of the three conditions true.

like image 208
aditya_gaur Avatar asked Jan 08 '13 04:01

aditya_gaur


1 Answers

Cars.filter(function(car) {
    return car.get("model") === 1998 ||
        car.get("color") === "Black" ||
        car.get("make") === "Honda";
});
like image 171
Lukas Avatar answered Oct 02 '22 19:10

Lukas