javascript - Firestore 网络代码示例给出了无效的参数类型

标签 javascript firebase gwt jsni google-cloud-firestore

我正在试用 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/

相关文章:

javascript - 如何隐藏/取消隐藏表格?

android - 如何在服务器端实现 firebase 云消息传递?

reactjs - base.database() 不是 firebase 中的函数错误与 react

GWT 编译 - 为什么只有一个 user.agent 选项后仍然有 5 个排列?

java - GWT、MVP - 许多小部件、最佳实践

java - 关于GWT开发模式的问题

javascript - `overflow:auto` 移动 View 中不隐藏滚动条

javascript - 使用 wp_enqueue_script() 在 Wordpress -functions.php 中添加 Javascript

javascript - 如何覆盖vuex存储数据

android - 如何使用两个子值在 Firebase 中进行搜索?