【发布时间】:2022-09-24 04:40:57
【问题描述】:
我有两个映射的项目列表。当我使用onClick={(e) => handleCheckClick(ele)} 单击div 时,我想在表格中显示单击的项目,但出现错误。
handleCheckClick函数
function handleCheckClick(ele) {
if (trayItems?.length > 0) {
settrayItems(
trayItems.map((item) => {
return { ...item, quantity: item.quantity + 1 };
})
);
} else {
settrayItems([...trayItems, ele]);
}
}
我如何将两个列表项映射到div
<div>
{
item && item.filter((person) => person.status == \"0\").map((ele) => {
return (
<div
className=\"newmo-card\"
style={styles.innerbox}
onClick={(e) => handleCheckClick(ele)}>
{`${ele.item}`}
<br />
<span> {`${ele.total_price}`}</span>
</div>
);
})
}
</div>
<Tray trayItems2={trayItems} trayItems1={trayPrice} />
点击项目表:
function Tray({ trayItems }) {
return (
<>
<div className=\"foo\">
<table>
{trayItems &&
trayItems.map((ele, index) => {
return (
<tr key={index}>
<td>{ele.item}</td>
<td>{ele.price}</td>
<td>{ele.quantity}</td>
</tr>
</table>
</div>
</>
);
}
检查sandbox,以便确定问题
-
您必须提供您的错误。另外,您提供的代码丢失太多,例如,
count来自<td>{count}</td>并且缺少一些}令牌。 -
我已经更新了这个问题,实际上我没有 {count} 的逻辑,如果你能帮助解决这个问题会很好@HuyPham
-
您也可以在这里分享您的商品数据。
-
[ { \"user_id\": 1, \"item\": \"biriani\", \"price\": \"50\", \"selling_price\": \"60\", \"created_at\ ": \"2022-08-29T10:12:58.000000Z\", \"updated_at\": \"2022-09-15T06:17:20.000000Z\", \"税\": \"5%\" , \"total_price\": \"80\", \"status\": 1 }, { \"user_id\": 5, \"item\": \"alfarm\", \"price\": \ "100\", \"sales_price\": \"120\", \"created_at\": \"2022-09-07T11:06:23.000000Z\", \"updated_at\": \"2022-09- 07T11:06:23.000000Z\", \"tax\": \"5%\", \"total_price\": \"140\", \"status\": 0 }, ]
-
@Kantivekariya 这是我在 console.log(item) 时得到的数据
标签: reactjs