Firebase snapshot link will not return data

I use firebase and have a list of people with specific priorities. In one of my functions, setting and getting priorities works fine. But in another, I can only set and try to get the return priority of the elements. 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 
+4
source share
1 answer

Actually, there are two different types of objects. A Firebase and DataSnapshot . When you call a new Firebase (), you get a Firebase link that allows you to write data (for example, using set or setPriority) or attach callbacks to read data (for example, using once or once).

These callbacks registered with on () or once () receive data through DataSnapshot, and you can call it .getPriority (). See Reading Data for more information .

For example, for your example to 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(); }); 
+2
source

Source: https://habr.com/ru/post/1446262/


All Articles