【发布时间】:2021-02-20 05:05:42
【问题描述】:
"@angular/fire": "^5.2.3",
我正在使用 AngularFireDatabase 来操作 firebase 中的数据。我需要在 Firebase 中检索和更新下表。我目前正在使用以下方法进行操作。有什么方法可以用来更好地查询吗?因为,我正在下载整个表格,然后再次上传。我不想下载整个提交列表,而只想将对象直接推送到提交数组。提前致谢。
// Get form submissions for a specific form
getFormSubmissions(key: string) {
this.userSubmissionsList = this.db.list('/form-submissions', ref => ref.orderByChild('formId').equalTo(key));
return this.userSubmissionsList;
}
getSingleFormForSubmission(key: string) {
this.submission = this.db.object('/form-submissions/' + key);
return this.submission;
}
this.formService.getFormSubmissions(this.formId).snapshotChanges().subscribe(response => {
let key = null;
response.forEach(item => {
const a: any = item.payload.toJSON();
key = item.key;
});
this.formService.getSingleFormForSubmission(key).valueChanges().subscribe(resp => {
if (resp.submission === undefined) { resp.submission = []; }
this.formSubs = resp;
});
});
推送数据如下:
this.formSubs.submission.push(data);
this.formService.submitUserValues(this.formSubs);
【问题讨论】:
标签: javascript angular firebase-realtime-database firebase-authentication angularfire2