javascript - How to remove a data from a child node created by push () -


background

in web app, each player object in database. when user selects player, instead of whole object being sent user's "selection" node under "user" parent node, player id inserted instead ease of reference.

code

i trying create web app such insert player id specific child node using push (). code :

//add player if not added if(!selected || selected[player.position<2) { ref3.push(player.id); } 

which results in following in database:

fantasyapp: {               players:{                    player 1 :{goals: 0,                               assists: 0,                               id: 1},                    player 2 :{goals: 1,                               assists: 3                               id:2}                               ...                       },              users:{                    user1:{selections:{fkajsdfjadfaj: 1                                       jfuueiuhfnalp: 2                                      }                          }                    ...                   }              } 

my isssue

my issue how delete user selected player database when user changes mind selection. below code have attempted:

//remove player if selected prevent player being selected    twice   if(!player.id === undefined){    ref3.remove(player.id);   }else{   return;   } 

but not effective. there way selected player removed user selection node if selected , inserted node if not selected? in effect work toggle: if not selected, player inserted, if selected, player removed?


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -