【问题标题】:Adding nested data to Firebase with VUEX使用 VUEX 将嵌套数据添加到 Firebase
【发布时间】:2018-08-18 10:34:43
【问题描述】:

我无法将我的“球员”数据存储到我的团队数据中。它确实与团队 ID 一起保存,但我希望它嵌套在团队内部。

所以我需要玩家实际添加并被推到空的“玩家”上......

我的 VUEX 商店中推送到 firebase 的代码是...

 firebase
        .database()
        .ref('teams/')
        .child(payload.id)
        .push(player)
        .then(user => {
          commit('updatePlayers', {
            players: payload.players
          });
        })
        .catch(error => {
          console.log(error);
        });
      // Reach out to firebase and store it      
    },

【问题讨论】:

    标签: javascript firebase vue.js vuex


    【解决方案1】:

    如果您将参考的完整路径放在前面,我相信它会起作用:

    firebase.database()
      .ref(`teams/${payload.id}/players`)
      .push(player)
      // .then, .catch, etc.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 2021-10-01
      • 2021-04-28
      • 2019-03-25
      • 2019-04-03
      • 2020-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多