Arrays VueJs和Firebase
如果我有一个Arrays VueJs和Firebase,arrays,firebase,vue.js,multidimensional-array,frontend,Arrays,Firebase,Vue.js,Multidimensional Array,Frontend,如果我有一个 projects: [ { project_id: this.project_id, project_desc: this.project_desc, project_info: this.project_info, residual: this.residual, to_start: this.to_start, to_end: this.to_end, sections: [ { section_i
projects: [
{
project_id: this.project_id,
project_desc: this.project_desc,
project_info: this.project_info,
residual: this.residual,
to_start: this.to_start,
to_end: this.to_end,
sections: [
{
section_id: this.section_id,
section_name: this.section_name,
section_info: this.section_info,
contract_value: this.contract_value,
approved_30_6_20: this.approved_30_6_20,
approved_20_21: this.approved_20_21,
total_approved_2021: this.total_approved_2021,
companies: [
{
company_id: this.company_id,
company_name: this.company_name,
outgoing: this.outgoing,
execution_rate: this.execution_rate,
contract_value: this.company_contract_value,
}
]
}
],
}
]
并尝试更新此项目数组中的特定数组。代码如下:
var database = db.collection('fields')
database.where('field_id', '==', this.$route.params.field_id).get().then(querySnapshot => {
querySnapshot.forEach(doc => {
database.doc(doc.id)
.update('projects', firebase.firestore.FieldValue.arrayUnion.apply(null, this.projects))
.then(docRef => {
this.$router.push('/')
})
})
})
我在data()字段中定义了一个数组,其中包含项目名称,因此使用了
this.projects
。您建议如何编辑database.where()
语句,以便我能够更新/添加特定项目的“sections”数组。提前感谢。您能否演示项目
文档与字段
集合的关系?另外,您在ArrayUnion上使用的apply()
方法是什么?fields是保存projects数组的主数组。apply方法是将null转换为随它一起传递的数组中的值的方法,这是一种扭转arrayUnion()方法的另一个问题的方法,因为它不接受嵌套数组