reactjs - 在地图内使用条件时出错
问题描述
items.map(item => {
return(
<tr key={item.id}>
<td>{item.id}</td>
<td>{item.heading}</td>
<td style={{width:"7.5%"}}>
<img className="bar-sm"src={item.image} alt="pic error" style=
{{width:'70px',height:'35px'}}/>
</td>
<td>
if (item.status === 0) {
return (
<>
<button type="button" className="btn btn-sm btn-secondary btn-toggle" data-toggle="button" aria-pressed="false" autocomplete="off"onClick={() =>Switch(item.status,item.id)}>
<div className="handle"></div>
</button>
</>
)
}
</td>
<td>{item.slug}</td>
<td>{item.category.name}</td>
解决方案
尝试使用这种 sintax "? :" 作为条件而不是 if/else
推荐阅读
- macos - ModuleNotFoundError 尽管使用 pip 安装
- python - 为什么我无法让 BeautifulSoup 像描述的那样工作?
- algorithm - 最大流量:如何在容量变化最小的情况下强制 f 个单位流动?
- javascript - 使用输入作为媒体轨道格式化 WebM 视频块/创建 MediaStream
- python - 需要帮助将数字和基数转换为二进制吗?
- python - excel将字符串转换为科学记数法
- r - 模式的蒙特卡罗模拟
- c++ - 当可以用 git 完成时,为什么要在 CMake 中添加版本号?
- c# - Xamarin如何在按钮单击MVVM时更改背景颜色
- javascript - 双击时删除奇数 ID Div 之前的 Div