문제

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