显示对象数组 Reactjs 中的座位
show the seats from an object array Reactjs
我在为我的组件使用地图函数时遇到错误。我想在以下代码中显示数据(li) tags
我的数组
const seatList = [
{ id: 0,
row:"A",
seats:[{id: 0, seatID: "c1",name:"A1" ,booked:"seat_disable"},
{id: 1, seatID: "c2",name:"A2" ,booked:""},
{id: 2, seatID: "c3",name:"A3" , booked:"seat_disable"},
]
},
{id: 1,
row:"B",
seats:[{id: 0, seatID: "c1",name:"A1" ,booked:""},
{id: 1, seatID: "c7",name:"B2" ,booked:"seat_disable"},
{id: 2, seatID: "c8",name:"B3" , booked:""},
]
},
]
代码块
<ul>
{seatList.map((rowsData, index) => {
<li className="st_seat_heading_row" key={index}>{rowsData.row}</li>
const seatLIst = rowsData.hasOwnProperty("seats") ?
rowsData.seats.map((seat,idx) => (
<li className={seat.booked} key={idx}>
<input type="checkbox" id={seat.seatID} name={seat.name}
onChange={e => this.handleChanged(e)}/>
<label htmlFor={seat.seatID} />
</li>
)) : null
})}
</ul>
我要显示如下
<ul>
{seatList.map((rowsData, index) => (
<>
<li className="st_seat_heading_row" key={index}>
{rowsData.row}
</li>
{rowsData.hasOwnProperty("seats") && (
<ul>
{rowsData.seats.map((seat, idx) => (
<li className={seat.booked} key={idx}>
<input
type="checkbox"
id={seat.seatID}
name={seat.name}
onChange={(e) => this.handleChanged(e)}
/>
<label htmlFor={seat.seatID} />
</li>
))}
</ul>
)}
</>
))}
</ul>
我在为我的组件使用地图函数时遇到错误。我想在以下代码中显示数据(li) tags
我的数组
const seatList = [
{ id: 0,
row:"A",
seats:[{id: 0, seatID: "c1",name:"A1" ,booked:"seat_disable"},
{id: 1, seatID: "c2",name:"A2" ,booked:""},
{id: 2, seatID: "c3",name:"A3" , booked:"seat_disable"},
]
},
{id: 1,
row:"B",
seats:[{id: 0, seatID: "c1",name:"A1" ,booked:""},
{id: 1, seatID: "c7",name:"B2" ,booked:"seat_disable"},
{id: 2, seatID: "c8",name:"B3" , booked:""},
]
},
]
代码块
<ul>
{seatList.map((rowsData, index) => {
<li className="st_seat_heading_row" key={index}>{rowsData.row}</li>
const seatLIst = rowsData.hasOwnProperty("seats") ?
rowsData.seats.map((seat,idx) => (
<li className={seat.booked} key={idx}>
<input type="checkbox" id={seat.seatID} name={seat.name}
onChange={e => this.handleChanged(e)}/>
<label htmlFor={seat.seatID} />
</li>
)) : null
})}
</ul>
我要显示如下
<ul>
{seatList.map((rowsData, index) => (
<>
<li className="st_seat_heading_row" key={index}>
{rowsData.row}
</li>
{rowsData.hasOwnProperty("seats") && (
<ul>
{rowsData.seats.map((seat, idx) => (
<li className={seat.booked} key={idx}>
<input
type="checkbox"
id={seat.seatID}
name={seat.name}
onChange={(e) => this.handleChanged(e)}
/>
<label htmlFor={seat.seatID} />
</li>
))}
</ul>
)}
</>
))}
</ul>