我正在为 firebase 的 flutter 电子商务购物车数据结构苦苦挣扎,构建数据的正确方法是什么?
现在我正在 firebase 上构建它:
cart_items = [
{
"id": 144,
"created_at": "2019-04-04 14:42:04",
"updated_at": "2019-04-04 14:42:04",
"cart_id": "3",
"client_id": "83",
"product_id": "6",
"quantity": "1",
"price": "1500",
"name": "Cucumber (2Pcs)",
"image": "products/es4eGjkgQ6MvzTaMyX4iXWjcSX03mVk3QB9oODWk.jpeg",
},
{
"id": 145,
"created_at": "2019-04-04 14:42:09",
"updated_at": "2019-04-04 14:42:09",
"cart_id": "3",
"client_id": "83",
"product_id": "5",
"quantity": "1",
"price": "2000",
"name": "Cauliflower",
"image": "products/lVZ31zORzltyVIDXhHoCWUgjTlal7cWd7pI8DL2V.jpeg",
}
]
但问题是我无法更新产品的数量字段。
答案 0 :(得分:1)
quantity 字段必须是整数或数字而不是字符串,然后您可以使用 FieldValue.increment(itemCount) 来更新数量值我也看到 cart_id、client_id、product_id、price 字段也是字符串,将其更改为整数或数字