简体   繁体   中英

Firebase transactions data

I'm using firebase for a game. Working with transactions and I'm getting a "object has no method 'val'" error.

It's annoying that their docs only have currentvalue+1 examples and not more complex.

With the game each player has x number of mins to submit the score. Naturally some scores will be submitted at the same time.

here's my script

var myScore=15;
var scoreRef = new Firebase('https://site.firebaseIO.com/arcade/games/keys/'+key+'/bonsai/'+bonsaiGameID+'/');
scoreRef.transaction(function(snapshot) {
    var leaderScore=snapshot.val().score;
    var leaderID=snapshot.val().leaderID; 
    if(myscore>leaderScore){
        scoreRef.push({data}) 
})

So 1st get the current score, if my score is higher push.

A transaction is not passed snapshot, but rather the value itself. The value can be a primitive (boolean, string or number) but can also be an object. It is basically the result of snapshot.val() rather than the snapshot itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM