Reputation: 176
I'm using firebase and have a list of people, with certain priorities. In one of my functions, setting and getting priorities is working fine. But in another, I can only set and trying to get the priority of the item returns 'dataSnapshot.getPriority() is not a function'.
var playersList = new Firebase('https://myfirebase.firebaseIO.com/players')
var winnerSnapshot = playersList.child(winner);
winnerSnapshot.setPriority('1300'); //This is working
var oldPriority = winnerSnapshot.getPriority(); //Not working
Upvotes: 4
Views: 2422
Reputation: 16309
There are actually two different types of object at play here. A Firebase reference, and a DataSnapshot. When you call new Firebase(), you get a Firebase reference which allows you to write data (e.g. using set or setPriority) or attach callbacks for reading data (e.g. using on or once).
These callbacks registered with on() or once() receive the data via a DataSnapshot and you can call .getPriority() on that. Check out the Reading Data docs for full details.
For example, to make your example work, you could do something like:
var winner = "somebody";
var playersListRef = new Firebase('https://myfirebase.firebaseIO.com/players')
var winnerRef = playersListRef.child(winner);
// You use a firebase reference to write data.
winnerRef.setPriority('1300');
// You can also use a firebase reference to attach a callback for reading data.
winnerRef.once('value', function(winnerSnapshot) {
// Inside your callback, you get a DataSnapshot that gives you access to the data.
var priority = winnerSnapshot.getPriority();
});
Upvotes: 2