Firebase - 取消回撥



本章將向你展示如何在 Firebase 中取消回撥。

取消特定事件型別的回撥

假設我們想要取消事件型別為 value 的回撥。

範例

var playersRef = firebase.database().ref("players/");

ref.on("value", function(data) {
   console.log(data.val());
}, function (error) {
   console.log("Error: " + error.code);
});

我們需要使用 off() 方法。這將刪除所有事件型別為 value 的回撥。

playersRef.off("value");

取消所有回撥

如需取消所有回撥,可使用 −

playersRef.off();
廣告
© . All rights reserved.