mardi 22 mars 2016

Using Firebase in my website

On Firebase, I am having the following issue; my data being structured as this:

myApp
- myList
    - KKJJXX...1        myString: "String One"
    - KKJJXX...2        myString: "String Two"
    - KKJJXX...3        myString: "String Three"

I want to make some JavaScript (in a web page of mine) to list the values of myString in the DB above. Here is what I came up with after digging the web. It works to a point, but not quite. I can see in the debugging console of my browser that I have got the data I want. I write my concerns more precisely after the script.

<script>
var ref = new Firebase("http://ift.tt/1U7avzp");

ref.on("value", function(snapshot) {
    for (x in snapshot.val()) {
        var xRef = new Firebase("http://ift.tt/1U7avzp"+x+"/");
        xRef.once("value", function(xsnapshot) {
            var name = xsnapshot.child("myString");
            console.log(name);
        });
    }
}, function (errorObject) {
    console.log("The read failed: " + errorObject.code);
});
</script>

In the debugging console I get this line(3 times):

Object { A: Object, Y: Object, g: Object }

And I can see that the A Object contains the information I am looking for (myString). What should I change in the script above to list directly the contents of myString on the console?




Aucun commentaire:

Enregistrer un commentaire