how to get firebase.database.Reference full path

后端 未结 3 2030
感动是毒
感动是毒 2021-01-17 22:54

consider

var adaRef = firebase.database().ref(\"users/ada\");

How can I get the full path of ref ? that is \"users/ada\" ?

3条回答
  •  隐瞒了意图╮
    2021-01-17 23:13

    That's surprisingly simple:

    adaRef.toString()
    

    Will print the full URL: https://firebaseio.com/users/ada

    So to just get the path, you substring it out of there. Two ways of doing that are:

    adaRef.toString().substring(firebase.database().ref().toString().length-1)
    

    or:

    adaRef.toString().substring(adaRef.root.toString().length-1)
    

    both will print /users/ada

提交回复
热议问题