How to get the key from the value in firebase

前端 未结 7 2001
挽巷
挽巷 2020-12-01 10:04

How do I get the key \"-KLpcURDV68BcbAvlPFy\" when I know the field \"name\" contains \"efg\" in the following structure in Firebase.

clubs
    -KLpcURDV68Bc         


        
相关标签:
7条回答
  • 2020-12-01 10:32

    I've figured out a very easy way to do this. You need to get the auto-generated key before you send it to firebase. So for my project I did something like the following:

    var database = firebase.database();
    var rootRef = database.ref();
    var autoId = rootRef.push().key
    rootRef.child(autoId).set({
    key: value,
    key: value,
    key: value,
    autoid: autoId
    })
    

    Now when i go to my child added function and take a snapshot, I can easily get to snapshot.val().autoid and store it in a variable or as a button attribute so that I can delete it later.

    0 讨论(0)
提交回复
热议问题