骨干收集WHERE子句与OR条件 [英] Backbone collection where clause with OR condition

查看:122
本文介绍了骨干收集WHERE子句与OR条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找这个相当长的一段时间,但无法获取的方式有一个用的地方或条件从句。例如,如果我有一个集合汽车,我要尽量做到以下几点:

  Cars.where({
            型号:1998,
            颜色:'黑',
            令:'本田'
          })

那么,上面会做的是寻找一个模式 1998年颜色制作本田

但我需要一个方式来获得汽车这要么三个条件如此。


解决方案

  Cars.filter(功能(车){
    返回car.get(模特)=== 1998年||
        car.get(色)===黑||
        car.get(使)===本田;
});

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.

解决方案

Cars.filter(function(car) {
    return car.get("model") === 1998 ||
        car.get("color") === "Black" ||
        car.get("make") === "Honda";
});

这篇关于骨干收集WHERE子句与OR条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆