Created
June 20, 2015 09:36
-
-
Save slashthinking/29295c19677eb52317e5 to your computer and use it in GitHub Desktop.
获得列表中的第一个
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeList(ref) { | |
var fruits = ["banana", "apple", "grape", "orange"]; | |
for (var i = 0; i < fruits.length; i++) { | |
ref.push(fruits[i]); | |
} | |
} | |
function getFirstFromList(ref, cb) { | |
ref.startAt().limit(1).once("child_added", function(snapshot) { | |
cb(snapshot.val()); | |
}); | |
} | |
// Running this should popup an alert with "banana". | |
function go() { | |
var testRef = new Firebase("https://example.firebaseIO-demo.com/"); | |
makeList(testRef); | |
getFirstFromList(testRef, function(val) { | |
alert(val); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment