Error: Typing on the input field of pick for each row just duplicates whatever value was entered in the qty field

Error: Typing on the input field of pick for each row just duplicates whatever value was entered in the qty field

所以我有这个字段,您可以在其中输入每一行的数量。然而,当我为选择添加另一个输入字段时,它正在工作,它只会复制在任一字段中输入的内容。我该如何解决?任何帮助将不胜感激。

加入购物车的商品:

const handleAdd = (id, name, price, size, cat, color, quan = null, pick) => {
    console.log("add", id, name, price, size, cat, color, quan, pick);
    const productExist = cartItems.find(
      (item) => item.id === id && item.color === color
    );

    if (productExist) {
      setCartItems(
        cartItems.map((item) =>
          item.id === id && item.color === color
            ? {
                ...productExist,
                quantity:
                  quan === "" || quan ? quan : +productExist.quantity + 1
              }
            : item
        )
      );
    } else {
      setCartItems([
        ...cartItems,
        { id, name, price, size, cat, color, quantity: 1, pick }
      ]);
    }
  };

您的代码中存在服务错误。

  1. 首先,您在调用 handleAdd 方法时没有按正确的顺序设置值。这就是为什么您面临问题中描述的问题。

  2. 其次,对象item中没有属性叫prodName,应该只是name.

Here 是可行的解决方案。