我是 Google Cloud FireStore 的新用户。
Document 对象有一个函数调用 onSnapshot附加 DocumentSnapshot 事件的监听器。
是否有一个函数可以删除该监听器(例如 offSnapshot)?如果没有我该如何实现?
最佳答案
对于 Web 和 Node.js SDK,调用 onSnapshot
会返回一个函数,您需要将该函数保存在变量中,并在您想要删除监听器时调用该函数。
var unsubscribe = db.collection("cities").onSnapshot(function (querySnaphot) {
// do something with the data.
});
// Stop listening to changes
unsubscribe();
其他 SDK 提供类似的功能。
参见https://firebase.google.com/docs/firestore/query-data/listen#detach_a_listener供引用。
关于firebase - 如何删除 DocumentSnapshot 事件的监听器 (Google Cloud FireStore),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46642652/