Skip to content

Instantly share code, notes, and snippets.

@yimengtianya
Created October 13, 2015 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yimengtianya/e6bb6e6c837847fbcc87 to your computer and use it in GitHub Desktop.
Save yimengtianya/e6bb6e6c837847fbcc87 to your computer and use it in GitHub Desktop.
Wilddog: 获取list中的第一个数据
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 Wilddog("https://example.wilddogio.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