【问题标题】:how to add key to chain mapping in react js如何在 React js 中添加键到链映射
【发布时间】:2022-06-12 02:06:22
【问题描述】:

我在映射数组时没有向导致此错误的子项添加键

react_devtools_backend.js:4026 Warning: Each child in a list should have a unique "key" prop.

这是我的数组结构:

[
  [
    { title: 'McRoyale', price: 70, count:5, totalPrice: 350 },
    { title: 'Big Mac', price: 55, count:1, totalPrice: 55 },
  ],
  [
    { title: 'Double Big Tasty', price: 99, count:2, totalPrice: 198 },
  ],
  [
    { title: 'Grand Chicken Premier', price: 72, count:3, totalPrice: 216 },
    { title: 'Spicy Chicken Fillet', price: 60, count:2, totalPrice: 120 },
  ]
]

这是我的代码:

<tbody>
          {cardItems.map((items) => (
            <tr>
              <td>
                {items.map((item) => (
                  <>
                    <b className='mc-red'>{item.title}</b> Item Price:{' '}
                    {item.price} LE, Item Count: {item.count}, Item Total Price:{' '}
                    {item.totalPrice} LE
                    <br />
                  </>
                ))}
              </td>
              <td>{calcPrice(items)} LE</td>
            </tr>
          ))}
        </tbody>

我怎样才能摆脱这个错误!

【问题讨论】:

标签: javascript arrays reactjs


猜你喜欢
  • 2022-08-04
  • 1970-01-01
  • 2020-03-03
  • 2023-01-07
  • 1970-01-01
  • 2023-02-02
  • 2021-10-16
  • 2022-12-29
  • 1970-01-01
相关资源
最近更新 更多