如何使此回叫工作?我已阅读过这些文件,但由于某些原因我无法弄明白?
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.");
}
});
Run Code Online (Sandbox Code Playgroud)
小智 13
弗兰克的解决方案非常适合您的问题.另一种选择是使用更新承诺.如果你一起做一堆操作,这在Firebase中通常就是这种情况,这是特别有用的.
这是一个使用承诺的例子
blast.update({ update: "I'm writing data" }).then(function(){
alert("Data saved successfully.");
}).catch(function(error) {
alert("Data could not be saved." + error);
});
Run Code Online (Sandbox Code Playgroud)
您的第二次调用update()
会在JavaScript控制台中引发此错误:
未捕获的错误:Firebase.update失败:第一个参数必须是包含要替换的子项的对象.(...)
第一个参数update
必须是一个对象,所以:
blast.update({ update: "I'm writing data" }, function(error) {
if (error) {
alert("Data could not be saved." + error);
} else {
alert("Data saved successfully.");
}
});
Run Code Online (Sandbox Code Playgroud)
作为参考,这是该update()
功能的文档.
归档时间: |
|
查看次数: |
8586 次 |
最近记录: |