获取Firebase参考的路径 [英] Get path of the Firebase reference

查看:130
本文介绍了获取Firebase参考的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Firebase路径(位置字符串中没有主机名部分,例如users / user1)给出Firebase参考?

现在我在Node.js中做了这样的工作,给出了Firebase引用 ref

  var url = require('url'); //标准的Node.js'url'模块。 
var location = url.parse(ref.toString())。pathname;

这是正确的方法还是存在更可靠的方法?
$ b

PS。我看到 ref.path.o 是包含可以构建路径的字符串的数组,但是我认为它不在公共API上,并且可能会改变?

解决方案

如果您想到Firebase上下文以外的地方,就会变成如何从URL获取路径?寻找这一点肯定会给出好的结果。他们可能会类似于你现在提出的。

另一种方法可能是依赖 Firebase的内置 root()方法来确定基本网址。

  var location = ref.toString()。substring(ref.root()。toString()。length); 


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?

解决方案

If you think of this outside of the context of Firebase, it becomes "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's built-in root() method to determine the base URL.

var location = ref.toString().substring(ref.root().toString().length);

这篇关于获取Firebase参考的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆