【发布时间】:2018-03-17 14:05:53
【问题描述】:
使用 firebase .push() 在指定引用的末尾创建一个带有随机键的新子节点,然后我们可以向它添加数据。但是我想在它之间添加数据。例如:
如果这是最初的情况:
{
"-L7kYVU5-CxkqBCmJLO-" : {
"articleCategory" : "tech",
"articleText" : "Hi , today lets talk about android....",
"articleTitle" : "new Android version announced",
"articleUrl" : "www.somewebsite.com/android_article",
"imgUrl" : "www.image.com"
},
"-L7kZozxhubLtJaOG1cy" : {
"articleCategory" : "tech",
"articleText" : "Apple Homepod - is the new product by Apple.....",
"articleTitle" : "Apple HomePod",
"articleUrl" : "www.somewebsite.com/apple_homepod",
"imgUrl" : "www.someotherimage.com"
}
}
我想要什么-
{
"-L7kYVU5-CxkqBCmJLO-" : {
"articleCategory" : "tech",
"articleText" : "Hi , today lets talk about android....",
"articleTitle" : "new Android version announced",
"articleUrl" : "www.somewebsite.com/android_article",
"imgUrl" : "www.image.com"
},
{
"-L7kYVU5-CxkqBOKAtO-" : {
"articleCategory" : "tech",
"articleText" : "The new iphone....",
"articleTitle" : "Iphone X review",
"articleUrl" : "www.somewebsite.com/iphoneX_article",
"imgUrl" : "www.otherimage.com"
},
"-L7kZozxhubLtJaOG1cy" : {
"articleCategory" : "tech",
"articleText" : "Apple Homepod - is the new product by Apple.....",
"articleTitle" : "Apple HomePod",
"articleUrl" : "www.somewebsite.com/apple_homepod",
"imgUrl" : "www.someotherimage.com"
}
}
所以基本上我想在第一个孩子之后而不是在通常使用 .push() 发生的列表末尾添加一个带有随机密钥(或任何密钥)的现有孩子之间的孩子
使用 orderByChild() 方法也可用于以特定的升序或降序更改接收数据的顺序(我可能对此有误,但这是我从文档中理解的)
我不知道这是否可能,但如果可以,请帮助我,或者如果不是,是否有任何解决方法可以做到这一点?
【问题讨论】:
-
请用您拥有的实际 JSON 替换您的伪数据结构(作为文本,请不要截图)。您可以通过单击Firebase Database console 中的“导出 JSON”链接来获取此信息。
-
完成,我希望现在清楚
标签: java android firebase firebase-realtime-database