繁体   English   中英

Array.prototype.filter() 期望在箭头函数 array-callback-return 结束时返回一个值

[英]Array.prototype.filter() expects a value to be returned at the end of arrow function array-callback-return

我在这里看到了类似的问题,但我无法弄清楚如何在涉及多个条件的情况下消除我的案例中的这个错误。

这是.filter()对象:

orders.filter((order) => {
  if (filterId === 0) {
    return order.status === 0 && order.type <= 3;
  } else if (filterId === 1) {
    return order.status === 0 && order.type === 0;
  } else if (filterId === 2) {
    return order.status === 0 && order.type === 1;
  } else if (filterId === 3) {
    return order.status === 0 && order.type === 2;
  }
}).map(...);

考虑将您的方法切换为 switch 而不是 if else 链。

 orders.filter((order) => { let value = 0; switch(filtedId){ case 0: value = order.status === 0 && order.type <= 3; case 1: value = order.status === 0 && order.type === 0; case 2: value = order.status === 0 && order.type === 1; case 3: value =order.status === 0 && order.type === 2; default: value = 0 } return value }).map(...);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM