我正在尝试从不断更新的孩子的 Firebase 数据中检索 JSON 数据。每次提交新数据时,快照键都会更改。(使用 sparkpost 将数据发送到 firebase)。我试图找出一种方法来构造我的检索,以便它可以从最新的键中获取。
var ref = new Firebase("https://watspark.firebaseio.com/raw-events/");
var _url = ('https://watspark.firebaseio.com/raw-events/');
// Retrieve new posts as they are added to our database
ref.on("child_added", function(snapshot, prevChildKey) {
var newPost = snapshot.val();
console.log(snapshot.val());
// console.log("text: " + newPost.text);
// console.log("Title: " + newPost.title);
// console.log("Previous Post ID: " + prevChildKey);
// var fireUrl = ("https://watspark.firebaseio.com/raw-events/" + snapshot.val() + "/0/msys/relay_message/content");
// var bigBoy = new Firebase(fireUrl);
// console.log("text: " + bigBoy.text);
var param = snapshot.key();
console.log(param);
});
ref.orderByChild("0/mysys/relay_message/content/text").on("child_added", function(snapshot) {
console.log(snapshot.key() + "was" + snapshot.val().text);
});
我的 JSON 数据结构如下:
snapshot.val();
{
0 {
mysys{
relay_message{
content
我该怎么做呢?谢谢