使用 VUEX 将嵌套数据添加到 Firebase

Adding nested data to Firebase with VUEX

我在将 'players' 的数据存储到我的团队数据中时遇到问题。它确实保存了团队 ID,但我希望它嵌套在团队内部。

所以我需要玩家实际添加并被推到空位 'players'...

我从我的 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      
    },

我相信如果你把引用的完整路径放在前面,它就会起作用:

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