Reputation: 11
I just found the Firebase API and really like it. However, I was looking at the Leader board sample and was wondering if add a new column:
userScoreRef.setWithPriority({ name:name, score:newScore, board:myboard }, newScore);
can I use this to separate the return to add it to different boards? Something like:
if (prevScoreName === null) {
if (myBoaard == 'Board1') { $("#leaderboardTable1").append(newScoreRow); }
if (myBoaard == 'Board2') { $("#leaderboardTable2").append(newScoreRow); }
if (myBoaard == 'Board3') { $("#leaderboardTable3").append(newScoreRow); }
if (myBoaard == 'Board4') { $("#leaderboardTable4").append(newScoreRow); }
if (myBoaard == 'Board5') { $("#leaderboardTable5").append(newScoreRow); }
}
else {
var lowerScoreRow = htmlForPath[prevScoreName];
lowerScoreRow.before(newScoreRow);
}
Or is there a better way to do this without rewriting the entire code 5 times?
Thanks
Upvotes: 0
Views: 424
Reputation: 2769
You should get the number of the current board and use that to add the score to different boards, like this:
if (prevScore === null) {
var leaderBoardTable = "leaderboardTable" + myBoard.charAt(myBoard.length-1);
$("#" + leaderBoardTable).append(newScoreRow);
}
Upvotes: 2