databaserefusers userRefonvalue functionsnapshot

Databaserefusers userrefonvalue functionsnapshot

This preview shows page 57 - 63 out of 63 pages.

userRef = firebase.database().ref("users"); userRef.on("value", function(snapshot) { snapshot.forEach(function(child) { console.log (child.key + ": " + child.val()); }); }); 57 Press Ctrl+Shift+J in Chrome for console window
Image of page 57
Listening to child events instead userRef.on("value", function(snapshot) {… Will retrieve a list of values in the path specified by userRef Not efficient, since entire list will be retrieved whenever changes occur userRef.on("child_added", function(…)) {… Firebase will callback for every existing child and new child added to the path userRef Other events: child_changed, child_removed 58
Image of page 58
Filtering data queryRef = firebase.database().ref("users"). orderByChild ( "name"). equalTo ("David"); queryRef.on("value", function(snapshot) { snapshot.forEach(function(child) { console.log(child.key + ": " + child.val()); }); }); 59
Image of page 59
Filtering data It also supports: orderByKey() orderByValue() 60
Image of page 60
orderByValue() example 61 queryRef = firebase.database().ref("users/500/scores") .orderByValue(); queryRef.on("value", function(snapshot) { snapshot.forEach(function(child) { console.log(child.key + ": " + child.val()); }); });
Image of page 61
Resources Add Firebase to your JavaScript Project Getting Started with Firebase on the Web ature=youtu.be Realtime Database: Installation & Setup in JavaScript, Read & Write Data … 62
Image of page 62
Resources Firebase REST API database/ Requests for Python - requests.org/en/master/user/quickstart/#make-a- request 63
Image of page 63

You've reached the end of your free preview.

Want to read all 63 pages?

  • Fall '14
  • Representational State Transfer, ECMAScript

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes