最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase get key value - Stack Overflow

programmeradmin5浏览0评论

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?

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?

Share Improve this question asked Feb 26, 2014 at 19:40 good_eveninggood_evening 21.7k69 gold badges198 silver badges306 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

Use key property

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

Documentation and examples here

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();
});
发布评论

评论列表(0)

  1. 暂无评论