如何访问iddoFeed节点并获取所有信息?

时间:2019-04-12 19:48:24

标签: javascript firebase firebase-realtime-database

enter image description here

firebase.database().ref('feeds').once('value').then((snapshot) => {

        let feeds = []

        snapshot.forEach((childItem) => {
            feeds.push({
                key: childItem.key,
                id: childItem.val().id_user,
                id_user: childItem.val().id_user,
                url: childItem.val().url,
                date_posted: childItem.val().date_posted,
                name: childItem.val().name,
                avatar:childItem.val().avatar,
                like_count: childItem.val().like_count,
                is_liked: childItem.val().is_liked,
                //comments: childItem.comments
            })
        })

1 个答案:

答案 0 :(得分:0)

在我看来,您似乎只需要解构iddoFeed对象即可。您的问题尚不清楚,但我认为这是您要尝试做的事情。

let feeds = []

    snapshot.forEach((childItem) => {
        feeds.push({
            key: childItem.key,
            id: childItem.val().iddoFeed.id_user,
            id_user: childItem.val().iddoFeed.id_user,
            url: childItem.val().iddoFeed.url,
            date_posted: childItem.val().iddoFeed.date_posted,
            name: childItem.val().iddoFeed.name,
            avatar:childItem.val().iddoFeed.avatar,
            like_count: childItem.val().iddoFeed.like_count,
            is_liked: childItem.val().iddoFeed.is_liked,

        })
    })