我有工作代码,并且 map 函数中的 if 语句没有什么问题,这里是代码
const SortableItem = SortableElement(CashItem);
const SortableList = SortableContainer(({items}) => {
return (
<div>
{items.map((cashitem, index) => (
<SortableItem key={`item-${index}`}
index={index}
isPayed={cashitem.isPayed}
date={cashitem.date}
name={cashitem.name}
realisticVal={cashitem.realisticVal}
realisticBalance={cashitem.realisticBalance}
optimisticBalance={cashitem.optimisticBalance}
optimisticVal={cashitem.optimisticVal}
changedName={(event) => this.nameChangedHandler(event, cashitem.id)}
isBlocked={(event) => this.handleChangeCheckbox(event, cashitem.id)}
delete={(event) => this.removeItem(event, cashitem.id)}
addNext={(event) => this.addNext(event, cashitem)}
realisticChange={(event) => this.realisticBalanceChangedHandler(event, cashitem.id)}
optimisticChange={(event) => this.optimisticBalanceChangedHandler(event, cashitem.id)}
dateChangedHandler={(event) => this.dateChangedHandler(event, cashitem.id)}
/>
))}
</div>
);
});
现在我想检查 if 语句仅在地图中的 cashitem 有状态可见时才呈现 cashitems isVisible 已经有 isVisible:true 或 false 我想做类似的事情
const SortableItem = SortableElement(CashItem);
const SortableList = SortableContainer(({items}) => {
return (
<div>
{items.map((cashitem, index) => (
if(cashitem.isVisible===true){
<SortableItem key={`item-${index}`}
index={index}
isPayed={cashitem.isPayed}
date={cashitem.date}
name={cashitem.name}
realisticVal={cashitem.realisticVal}
realisticBalance={cashitem.realisticBalance}
optimisticBalance={cashitem.optimisticBalance}
optimisticVal={cashitem.optimisticVal}
changedName={(event) => this.nameChangedHandler(event, cashitem.id)}
isBlocked={(event) => this.handleChangeCheckbox(event, cashitem.id)}
delete={(event) => this.removeItem(event, cashitem.id)}
addNext={(event) => this.addNext(event, cashitem)}
realisticChange={(event) => this.realisticBalanceChangedHandler(event, cashitem.id)}
optimisticChange={(event) => this.optimisticBalanceChangedHandler(event, cashitem.id)}
dateChangedHandler={(event) => this.dateChangedHandler(event, cashitem.id)}
/>
}
))}
</div>
);
});