2017-10-09 73 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 –