gpt4 book ai didi

javascript - 在 Firebase 中处理多个 URL 以供引用?

转载 作者:行者123 更新时间:2023-11-30 16:02:07 25 4
gpt4 key购买 nike

我有一个情况,有多个用户,所有用户都分配有唯一的 hashId,这使得他们的 URL 不同。

users/hashId/bla/blah

这些 URL 的唯一区别是 hashId 值。

当我的客户端更新 firebase 中的数据时,我需要将服务器交互应用到 Node 端的 child_added 事件监听器。

App can have any number of users, how to scale child_added for each URL? Is there any concept of dynamic Urls?

由于对每个 URL 的引用都是新的,我不确定这种情况。此外,我不希望使用 for 循环来进行动态事件绑定(bind)。

P.S:对 Firebase 比较陌生。

最佳答案

很难从你的描述中确定,但你是在找这个吗?

var db = firebase.database();
var ref = db.ref("users");
ref.on("child_added", function(snapshot) {
console.log(snapshot.child("bla/blah").val());
});

如果您只想获取每个用户的 blah 值,那么您应该修改数据模型以分离数据:

users_bla_blah
$uid
valueOfBlaBlah
users
$uid
otherProps

然后你可以简单地监听:

var ref = db.ref("users_bla_blah");
ref.on("child_added", function(snapshot) {
console.log(snapshot.val());
});

关于javascript - 在 Firebase 中处理多个 URL 以供引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37570524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com