javascript - 在 JavaScript 中将 const 转换为函数 - React
问题描述
如何将他的常数转换为函数?我认为最好有一个常数这么长的函数。它先做一个过滤器,然后再做一个地图。
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);
});
}
推荐阅读
- wordpress - 网站在 wordpre 请求上返回错误
- javascript - 每次按下下一个问题按钮时,我都想将其更改为数组中写入的内容
- laravel - 调用数组 Laravel 上的成员函数 paginate()
- mysql - 查询酒店可预订房间
- python - 使用 matplotlib 在 x 轴上突出显示特定日期
- c++ - Qt SLOT 不是由 QTest 环境中的 std::async 发出的信号触发的
- sql-server - 错误 1105 - 为什么 SQL 说 PRIMARY 文件组已满,而实际却没有?
- bash - 在bash中比较并丢弃数组中的元素
- angular - 如何使用 Float 修复角度 ngFor
- flutter - 如何设置 Flutter 文本最大长度值?