Firebase更新回调以检测错误和成功 [英] Firebase update callback to detect error and sucssess

查看:101
本文介绍了Firebase更新回调以检测错误和成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I make this call back work? I have read the documents but I just cant figure it out for some reason?

   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.");
  }
});

推荐答案

Frank的解决方案非常适合您的问题.另一种选择是使用更新承诺.如果您要一起执行一堆操作(在Firebase中通常就是这种情况),则该功能特别有用.

Frank's solution is perfect for your question. Another option is to use the update promise. It's particularly useful if you're doing a bunch of operations together which is often the case in Firebase.

以下是使用承诺的示例

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

这篇关于Firebase更新回调以检测错误和成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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