Firebase 更新回调以检测错误和成功

标签 firebase

我如何使这个回调工作?我已经阅读了文档,但由于某种原因我无法弄清楚?

   var ref = new Firebase("https://xxx.firebaseio.com/public/"+$scope.uid+"/shows/");
var blast = ref.child(show_title);

blast.update({
"show_title": show_title,
"show_image": show_image,
"show_description": show_description,
"show_email": show_email,
"time": Firebase.ServerValue.TIMESTAMP
});

 blast.update("I'm writing data", function(error) {
   if (error) {
    alert("Data could not be saved." + error);
  } else {
    alert("Data saved successfully.");
  }
});

最佳答案

弗兰克的解决方案非常适合您的问题。另一种选择是使用更新 promise 。如果您同时进行一系列操作(在 Firebase 中经常出现这种情况),这将特别有用。

这是一个使用 promise 的示例

blast.update({ update: "I'm writing data" }).then(function(){
  alert("Data saved successfully.");
}).catch(function(error) {
  alert("Data could not be saved." + error);
});

关于Firebase 更新回调以检测错误和成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33610616/

相关文章:

android - 将 firebase 添加到 android studio 时,gradle 不同步

javascript - 传递异步错误的正确方法

android - 空对象引用上的 java.util.ArrayList.size()'

android - 您的动态链接路径前缀未在 firebase.json 中配置

带有查询参数的 Firebase 动态链接

firebase - 如何刷新 Firebase streambuilder 并减少文档读取次数

javascript - Firebase Cloud Function 错误,函数返回未定义、预期 Promise 或值

Swift 如何为用户使用 Firebase 投票添加 5 星级评分

java - 如何在实时数据库firebase中获取第一个子节点

android - 应用程序被杀死后推送通知