It's easy to get value:

    firebase_instance.limit(100).on("child_added", function(data) {
        var value = data.val();
    });

but how to get a key associated with that value?

有帮助吗?

解决方案

Each of your Firebase .on(...) callbacks are going to be invoked with a Firebase DataSnapshot. To get the name for the location of that DataSnapshot, try using the name() method.

For example:

firebase_instance.limit(100).on("child_added", function(snap) {
  var name = snap.name();
});

其他提示

Use key property

firebase_instance.limit(100).on("child_added", function(snap) {
  var name = snap.key;
});

Documentation and examples here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top