我想在我的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);
最佳答案
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);
关于javascript - Lodash 与过滤器中的 OR 逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136924/