我正在創建一個顫振應用程式,并且有一個包含名稱、電子郵件、uid 和購物車的用戶模型。我創建了一個 CartController 擴展 GetxController 以將專案添加到購物車并從購物車中洗掉特定專案。但是,我需要創建一個函式,從包含購物車專案作為物件的購物車中洗掉所有專案。我知道可以使用 FieldValue.arrayRemove() 洗掉特定的購物車專案,但我想知道如何從陣列中洗掉所有元素。
uj5u.com熱心網友回復:
您實際上是在嘗試將cart陣列設定為空陣列。您可以使用檔案update中的方法:
final docRef = db.collection("collection").doc("docId");
docRef.update({"cart": []}).then(
(value) => print("DocumentSnapshot successfully updated!"),
one rror: (e) => print("Error updating document $e"));
uj5u.com熱心網友回復:
您可以在陣列變數上使用 .clear() 。
嘗試
FieldValue.clear()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/495063.html
