我如何使这个回调工作?我已经阅读了文档,但由于某种原因我无法弄清楚?
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/