【发布时间】:2017-02-10 12:24:07
【问题描述】:
我已经从一个数组修改了一个 firebase 结构
{
"posts" : [
{
"code" : "BAcyDyQwcXX",
"caption" : "Lunch #hamont",
"likes" : 56,
"id" : "1161022966406956503",
"display_src" : "https://test1.jpg"
},
{
"code" : "BAcJeJrQca9",
"caption" : "Snow! ⛄️????❄️ #lifewithsnickers",
"likes" : 59,
"id" : "1160844458347054781",
"display_src" : "https://test2.jpg"
},
]
}
到“扁平化”对象
{
"posts" : {
"1161022966406956503" : {
"code" : "BAcyDyQwcXX",
"caption" : "Lunch #hamont",
"likes" : 56,
"display_src" : "https://test1.jpg"
},
"1160844458347054781" : {
"code" : "BAcJeJrQca9",
"caption" : "Snow! ⛄️????❄️ #lifewithsnickers",
"likes" : 59,
"display_src" : "https://test2.jpg"
}
}
}
现在希望重构以下代码以适应处理 firebase 对象而不是数组:
const { postId } = this.props.params;
const i = this.props.posts.findIndex((post) => post.code === postId);
我该怎么做?
【问题讨论】:
标签: reactjs firebase firebase-realtime-database