【发布时间】:2017-02-06 08:04:44
【问题描述】:
我在 Firebase 中有一个名为 Events 的节点。它由子对象组成,例如:address、description、longitude、latitude。在用户删除事件节点之前,我想将其复制到同一个数据库中的一个名为 eventsDeleted 的节点中。
这是删除节点的代码:
removeEvent(eventId, groupId) {
return new Promise((resolve, reject)=> {
this.eventRef.child(groupId).child(eventId).remove();
resolve();
});
}
这是创建节点的代码:
addEvent(data:any) {
console.log('Form data', data.group);
let localEventRef = firebase.database().ref('events').child(data.group.split(',')[1]);
let storageRef = firebase.storage().ref();
let file = data.image;
let uploadTask = storageRef.child('eventImages/' + UuidGenerator.generateUUID()).put(file);
uploadTask.on('state_changed', function (snapshot) {
}, function (error) {
// Handle unsuccessful uploads
console.error(error);
}, function () {
// Handle successful uploads on complete
let downloadURL = uploadTask.snapshot.downloadURL;
let keyOfNewEvent = localEventRef.push(
new Event(
null,
firebase.app().auth().currentUser.uid,
data.description,
data.location.address,
0
)
).key;
localEventRef.child(keyOfNewEvent).update({eventId: keyOfNewEvent});
});
}
不要介意上传图片的代码。如果可能的话,我只需要一种方法来复制整个节点,然后将其粘贴到数据库中的某个位置。提前致谢。
【问题讨论】:
-
使用angular.copy() 并用它创建一个新项目
标签: javascript angularjs firebase firebase-realtime-database