admin管理员组文章数量:1291043
How to get the Firebase path (location string without the hostname part such as "users/user1"
) given the Firebase reference? I can't find in the docs and tried to search but no luck.
Now I did like this in Node.js, given Firebase reference ref
:
var url = require('url'); // standard Node.js 'url' module.
var location = url.parse(ref.toString()).pathname;
Is this the correct way to do or there exist a more reliable way?
PS. I saw ref.path.o
is the array containing the strings that can construct the path but I think it's not on the public API and may subject to change?
How to get the Firebase path (location string without the hostname part such as "users/user1"
) given the Firebase reference? I can't find in the docs and tried to search but no luck.
Now I did like this in Node.js, given Firebase reference ref
:
var url = require('url'); // standard Node.js 'url' module.
var location = url.parse(ref.toString()).pathname;
Is this the correct way to do or there exist a more reliable way?
PS. I saw ref.path.o
is the array containing the strings that can construct the path but I think it's not on the public API and may subject to change?
1 Answer
Reset to default 10If you think of this outside of the context of Firebase, it bees "How do I get just the path from a URL?" Searching for that is bound to give good results. They'll likely be similar to what you came up with now.
Another approach might be to depend on Firebase 2.x SDK's root()
method, which later became the root
property in Firebase 3 SDK onwards to determine the base URL.
// For Firebase 2.x SDK
var location = ref.toString().substring(ref.root().toString().length);
// For Firebase 3 SDK and later
var location = ref.toString().substring(ref.root.toString().length);
本文标签: javascriptGet path of the Firebase referenceStack Overflow
版权声明:本文标题:javascript - Get path of the Firebase reference - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741522846a2383290.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论