首页 > 解决方案 > 在地图内使用条件时出错

问题描述

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>

标签: reactjs

解决方案


尝试使用这种 sintax "? :" 作为条件而不是 if/else


推荐阅读