过滤器中的Lodash和OR逻辑

时间:2017-05-23 13:58:36

标签: javascript lodash

我想在我的lodash _.filter

中实现这个逻辑
if (bolMine && !bolUnassigned)
{
    o => o.AssignedDriver == CurrentLoggedOnUser;
}
else if (bolMine && bolUnassigned)
{
     o => (o.AssignedDriver == CurrentLoggedOnUser || o.AssignedDriver == 0);
}
else if (!bolMine && bolUnassigned)
{
     o => o.AssignedDriver == CurrentLoggedOnUser;
}


if (bolExvat)
{
    o => o.ExVatOrder == bolExtVat;
}

if(intCategory > 0)

{

    o => o.OrderCategory == intCategory

}

如何将此转换为我的iteratee?

 this.filteredOrders = _.filter(this.orders, iteratee);

1 个答案:

答案 0 :(得分:1)

function filterOrders(o) {
    if (bolMine && !bolUnassigned)
    {
        return o.AssignedDriver == CurrentLoggedOnUser;
    }
    else if (bolMine && bolUnassigned)
    {
        return (o.AssignedDriver == CurrentLoggedOnUser || o.AssignedDriver == 0);
    }
    else if (!bolMine && bolUnassigned)
    {
        return o.AssignedDriver == CurrentLoggedOnUser;
    }


    if (bolExvat)
    {
        return o.ExVatOrder == bolExtVat;
    }

    if(intCategory > 0)
    {
        return o.OrderCategory == intCategory
    }
}

this.filteredOrders = _.filter(this.orders, filterOrders);