您可以在 child_added 侦听器中使用 firebase 中的通配符或 glob 吗?

can you use a wildcard character or globs in firebase with the on child_added listener?

我基本上想做一个 grandchild_added 事件侦听器。

查看子文档和文档,我无法弄清楚是否有办法在引用中设置通配符,以便它监视整个引用模式。

https://www.firebase.com/docs/web/api/firebase/child.html https://www.firebase.com/docs/web/api/query/on.html

给出的 firebase 数据是这样的:

-messages
  -roomA
    -hi a
    -hello everyone a
  -roomB
    -hi b

例如,我可以这样做吗?

var roomMsgs = new Firebase("https://" + firebase_host + ".firebaseio.com/messages/*/");

roomMsgs.on('child_added', function(childSnapshot, prevChildKey) {
  // handle that a new message was added
});

如果可以的话,我不想为每个房间单独添加一个单独的 ref,因为那样会有点复杂,我不确定这样做是否也能发挥同样的作用。

没有。 child_added 事件在您将其附加到的位置下一级侦听。

如果您附加到用户的 messages 位置,Firebase 将在消息添加到房间时触发 child_changed 事件和 value 事件。