如何将他的常数转换为函数?我认为最好具有一个恒定的功能。它先过滤,然后再映射。

const cells = upcoming
  .filter(clinic => {
    if (showAll) return true;
    if (
      clinic.staff.teamLeadStaffed !== null &&
      clinic.staff.techsStaffed.length === clinic.staff.techsNeeded
    )
      return false;
    return true;
  })
  .map(clinic => {
    const [color, reason] = this.getColorAndReason(clinic);


我尝试了类似的方法,但是没有用

  renderCell(upcoming) {
    return (
      upcoming
        .filter(clinic => {
          if (showAll) return true;
          if (
            clinic.staff.teamLeadStaffed !== null &&
            clinic.staff.techsStaffed.length === clinic.staff.techsNeeded
          )
            return false;
          return true;
        })
        .map(clinic => {
          const [color, reason] = this.getColorAndReason(clinic);
    )
  }

最佳答案

function cells() {
  return upcoming
    .filter(clinic => {
      if (showAll) return true;
      if (
        clinic.staff.teamLeadStaffed !== null &&
        clinic.staff.techsStaffed.length === clinic.staff.techsNeeded
      )
        return false;
      return true;
    })
    .map(clinic => {
      const [color, reason] = this.getColorAndReason(clinic);
    });
}

09-13 02:19