2017-10-09 107 views

回答

4

如果使用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以供参考。

+0

它工作正常。谢谢@Scarygami –