如何删除DocumentSnapshot事件的侦听器(Google Cloud FireStore) [英] How to remove listener for DocumentSnapshot events (Google Cloud FireStore)

查看:55
本文介绍了如何删除DocumentSnapshot事件的侦听器(Google Cloud FireStore)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google Cloud FireStore的新手.

I'm new in Google Cloud FireStore.

Document对象具有一个函数调用 onSnapshot 为DocumentSnapshot事件附加一个侦听器.

The Document object has a function call onSnapshot to attaches a listener for DocumentSnapshot events.

是否具有删除该监听器的功能(例如offSnapshot)?如果没有,我该如何实施?

Is there a function to remove that listener (like offSnapshot)? If not how can I implement it?

推荐答案

对于Web和node.js SDK,调用onSnapshot返回一个需要保存在变量中的函数,并在要删除时调用听众.

In case of the web and node.js SDK, calling onSnapshot returns a function that you need to save in a variable and call when you want to remove the listener.

var unsubscribe = db.collection("cities").onSnapshot(function (querySnaphot) {
  // do something with the data.
});


// Stop listening to changes
unsubscribe();

其他SDK提供类似的功能.

The other SDKs offer similar functionality.

请参见 https://firebase.google.com/docs/firestore /query-data/listen#detach_a_listener 供参考.

这篇关于如何删除DocumentSnapshot事件的侦听器(Google Cloud FireStore)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆