我使用firebase作为DB和Angular来创建后端。
当我想更新数据库中的某个特定项目时,我遇到了一些问题。
我的数据库是这样的:
--mydomain
----posts
--------POST LIST1 (crazy number and letter are display)
------------author
------------imageDetails THIS IS WAHT SHOULD BE UPDATED)
------------etc
--------POST LIST2 (crazy number and letter are display)
------------author
------------imageDetails
------------etc
...
----users
--------name
--------email
--------id
我希望能够更新CURRENT项目(帖子)的表格图片
但目前我尝试更新时会这样做:
--mydomain
----posts
--------POST LIST1 (crazy number and letter are display)
------------author
------------imageDetails
------------etc
--------POST LIST2 (crazy number and letter are display)
------------author
------------imageDetails
------------etc
--------imageDetails(THIS IS WHERE ITS WRONG)
...
----users
--------name
--------email
--------id
我原来的代码是:
var firebaseRef = firebase.database().ref().child('posts/');
我也尝试以下方法:
var firebaseRef = firebase.database().ref('posts/' + posts.key +'/test');
没有成功,我的帖子没有定义'
完整代码如下:
app.controller('myController', ['$scope','$firebaseStorage',function($scope, $firebaseStorage) {
var ref = firebase.database().ref().child("posts");
// Create a Firebase Storage reference
var storage = firebase.storage();
var firebaseRef = firebase.database().ref('posts/' + posts.key +'/test').push().key;
var storageRef = storage.ref();
var filesRef = storageRef.child('files');
$scope.uploadFile = function(file) {
console.log("Let's upload a file!");
console.log($scope.file);
var storageRef = firebase.storage().ref().child(file.name).put(file);
storageRef.on('state_changed', function(snapshot) {
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
}, function() {
//handle error
}, function() {
//url of storage file
var downloadURL = storageRef .snapshot.downloadURL;
firebaseRef.update({'url':downloadURL})
// firebaseRef.update().ref().child('posts').child({'oui':downloadURL});
// const dbref = firebase.database().ref().child('posts').child(uid);
console.log(downloadURL);
});
};
}]);
我怎样才能做到这一点?我一直试图使用推送,但它并没有改变任何东西。
感谢您的帮助。
答案 0 :(得分:0)
ReaderT