javascript - VueJS + Firebase saving an Array with Keys -
some context... have list of players in hockey league. each game played want save gamesheet players of home team , visiting team include game stats. want player .key full list of players match player .key of stored gamesheet.
 issue i'm having storing array of home/visitor teams firebase.   array 'hometeam' following:
[ { "name": "steve", "number": "10", "position": "f", ".key": "-krbkovnje2uxu2h1aec" }, { "name": "carl", "number": "32", "position": "f", ".key": "-krbkovnje2uxu2h1aec" } ]
i can save individual records following:
gamesheetref.child(gameinfo['.key']).child('home').child(this.hometeam[0]['.key']).set({name: this.hometeam[0].name})
this saves correct structure in firebase:
 - gamesheet   - -konukq9pf7ksy9jvgo3      - home        - -krbkovnje2uxu2h1aec           - name: "steve"
how can save entire array this, using .key(s) array?
update: solved foreach, it's running client side i'm not sure best implementation. rather send entire array firebase @ once, otherwise move code server side nuxt.
this.hometeam.foreach (function(player) {     gamesheetref.child(gameinfo['.key']).child('home').child(player['.key']).set({name: player.name})     });       
 
Comments
Post a Comment