我正在试用 Firebase 的新 Firestore。当我运行来自 https://firebase.google.com/docs/firestore/manage-data/add-data?authuser=0 的代码示例时, 我收到一个错误。
// Add a new document with a generated id.
db.collection("cities").add({
name: "Tokyo",
country: "Japan"
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
Exception caught: (FirebaseError) : Function CollectionReference.add() requires its first argument to be of type object, but it was: a custom Object object
编辑: 抱歉,我没有提到我正在使用 GWT 和 JSNI,它在没有 gwt 的情况下工作正常
最佳答案
这可能是跨窗口问题:GWT 代码在 iframe 中运行;如果 Firebase 正在寻找“裸对象”,它可能会比较对象的构造函数,如果对象跨越 iframe 边界,这将不是预期的构造函数。
也许尝试使用 new $wnd.Object()
而不是 {}
或 new Object()
。
关于javascript - Firestore 网络代码示例给出了无效的参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46620162/