Javascript 如何将具有嵌套数组的对象保存到Firestore

Javascript 如何将具有嵌套数组的对象保存到Firestore,javascript,vue.js,google-cloud-firestore,Javascript,Vue.js,Google Cloud Firestore,我有以下对象,希望将其保存到Firestore { “集团”:[{ “返回”:“值”, “tStamp”:{ “秒”:1574944200, “纳秒”:0 }, “例子”:[{ “答案”:“一些文字”, “示例”:“更多文本” }, { “答案”:“一些文字”, “示例”:“更多文本” }], “正面”:“价值” }, { “返回”:“值”, “tStamp”:{ “秒”:1575148500, “纳秒”:0 }, “正面”:“价值” }, { “返回”:“值”, “tStamp”:{ “秒”:

我有以下对象,希望将其保存到Firestore

{
“集团”:[{
“返回”:“值”,
“tStamp”:{
“秒”:1574944200,
“纳秒”:0
},
“例子”:[{
“答案”:“一些文字”,
“示例”:“更多文本”
}, {
“答案”:“一些文字”,
“示例”:“更多文本”
}],
“正面”:“价值”
},
{
“返回”:“值”,
“tStamp”:{
“秒”:1575148500,
“纳秒”:0
},
“正面”:“价值”
},
{
“返回”:“值”,
“tStamp”:{
“秒”:1577831400,
“纳秒”:0
},
“正面”:“价值”
},
]
}
尝试使用
db.collection('cardsb')保存它。添加(对象)
会导致错误:

vue.runtime.esm.js?2b0e:619[vue warn]:v-on处理程序中出现错误:“FirebaseError:[代码=无效参数]:函数DocumentReference.set()使用无效数据调用。不支持的字段值:未定义”

我正在寻找一种将上述数据(具有嵌套数组的对象)存储到firestore中的方法。我可以在Firestore中手动存储它。见下文:

以下是生成对象的方式:

cons () {
  const nbrGroups = this.cards.length
  for (let i = 0; i < nbrGroups; i++) {
    var object = []
    const nbrItems = this.cards[i].group.length
    for (let item = 0; item < nbrItems; item++) {
      var inputs = document.querySelectorAll('#' + this.cards[i].group_name.replace(/\s/g, '') + item + 'A #inFront, #' + this.cards[i].group_name.replace(/\s/g, '') + item + 'A #inBack, #' + this.cards[i].group_name.replace(/\s/g, '') + item + 'A #inAnswer, #' + this.cards[i].group_name.replace(/\s/g, '') + item + 'A #inExample')
      const examples = []
      if (inputs.length !== 2) {
        for (let i = 2; i < inputs.length; i++) {
          examples.push({ answer: inputs[i + 1].value, example: inputs[i].value })
          i++
        }
        object.push({
          back: inputs[1].value,
          delayed_till: this.cards[i].group[item].delayed_till,
          examples,
          front: inputs[0].value
        })
      } else {
        object.push({
          back: inputs[1].value,
          delayed_till: this.cards[i].group[item].delayed_till,
          front: inputs[0].value
        })
      }
    }
    console.log(JSON.stringify({ group: object }))
    console.log(JSON.stringify(object) === JSON.stringify(this.cards[i].group))
    console.log(JSON.stringify(this.cards[i].group))
    console.log(JSON.stringify(this.cards[i].id))

    db.collection('cardsb').add({ group: object })
  }
}
cons(){
常量组=this.cards.length
for(设i=0;i<0;i++){
变量对象=[]
const nbr items=this.cards[i].group.length
对于(设项=0;项<0;项++){
var inputs=document.queryselectoral(“#”+this.cards[i].组名.replace(/\s/g),)+item+'A#inFront,#')+this.cards[i].组名.replace(/\s/g,)+item+'A#inBack,#'+this.cards[i].组名
常量示例=[]
if(inputs.length!==2){
for(设i=2;i
您是否可以编辑问题以显示再现问题的所有代码?我们需要能够准确地看到您是如何构建
对象的。错误消息告诉您,该对象中的某个对象的值
未定义
,Firestore将不接受该值。@Doug我更新了我的问题这里仍然没有足够的信息。我们还需要能够看到所有源数据,这意味着
this.cards
。我认为您只需要通过查找代码可能将
未定义的
放在某个值中的位置来调试它。如果您需要这方面的帮助,您必须提供一个MCVE,任何人都可以使用该副本来解决特定问题。如果是这种情况,下面的代码如何将数据正确地记录到控制台
console.log(JSON.stringify({group:object}))
,但是下面的代码会产生一个错误
db.collection('cardsb')。add({group:object})
console.log不关心某些数据是否未定义。Firestore不会接受它。