angularjs - Firebase get value out of array -


I am creating a realtime app with AngularJS and Firebase. I am storing an array of data (players) below, you can see a sample of your data structure.

Enter image details here

I I can get all the players, but how do I get the player 'test'? Key is a generated value:

  Game.find (gameId). Child ('/ player /') Push (player);  

Then I thought, why should I just set the 'updates' '/ players /' + name and name there. But unfortunately, I'm returning objects within an object:

  {players: {"name": "...", "test": "moretest"}}  

I can use these properties, but I can not loop on them because it is not an array.

So basically what I want to do is "linq-wise" pulling out a player from an array.

Game.find (gameId) .child ('/ players /') Where (name == ...); Thanks

Png "alt =" Enter the image details here ">

Right path with storing you on the right name Instead of using an push to generate an ID, the player will need to make sure that your player names are unique, otherwise you will be able to adjust the two players with the same name The risk of not being I take it.

Every key should be worth the firebase, so the best way is to store a list of players where you want them to be accessible by the player name, just set them in the Boolean values ​​like 'right' :

  Game.find (gameId). Child ('/players').child(player).set(true);  

Comments