英文:
Android/Firebase Create a folder as a subfolder of a unique folder, both are created at the same time
问题
问题: 我想要将照片添加到帖子中,部分操作成功,但是"images"文件夹是单独创建的,而不是在绿色标记的唯一文件夹中。
databaseReference = FirebaseDatabase.getInstance().reference.child("posts")
private fun SendLink(url: String) {
val hashMap: HashMap<String, String> = HashMap()
hashMap["link"] = url
databaseReference!!.child("green下划线标记的文件夹名").child("images").push().setValue(hashMap).addOnCompleteListener {
progressDialog!!.dismiss()
choosenImages!!.text = "成功添加图片。"
addImagesBT.visibility = View.GONE
ImageList.clear()
}
}
问题: 如何将/创建名为images的文件夹作为绿色下划线标记文件夹的子文件夹?
英文:
Problem: I want to add photos to the post, it partially works, but the "images" folder is created separately, instead of in a unique folder marked in green
databaseReference = FirebaseDatabase.getInstance().reference.child("posts")
private fun SendLink(url: String) {
val hashMap: HashMap<String, String> = HashMap()
hashMap["link"] = url
databaseReference!!.child("images").push().setValue(hashMap).addOnCompleteListener {
progressDialog!!.dismiss()
choosenImages!!.text = "Succesfully added images."
addImagesBT.visibility = View.GONE
ImageList.clear()
}
}
Question: How to move / create "images" folder as a subfolder of green underlined folder?
答案1
得分: 0
在实时数据库中,实际上没有任何“文件夹”。只有可以包含子节点的节点。没有在节点之间“移动”数据的操作。您可以从源节点读取数据,写入目标节点,然后删除原始节点。
如果您创建的节点显示在错误的位置,这意味着您可能只需更改写入位置。当前,您的代码正在将新的子节点添加到“images”下的随机生成节点中。如果您想要改为写入“posts”,只需更改推送数据的节点名称。注意创建“Reference”对象的方式,您在调用push()
时会使用该引用,该引用将是新生成的节点名称将被写入的根节点。
英文:
In Realtime Database, there are not actually any "folders". There are just nodes that can contain child nodes. There are no operations to "move" data between nodes. What you can do instead is read data from a source node, write it to a destination node, then delete the original node.
If a node that you create is showing up in the wrong location, that means you should probably just change the location where it's being written. Right now, your code is adding new child nodes to randomly generated nodes under "images". If you want to write to "posts" instead, simply change the name of the node where you push the data. Pay attention to how you create the Reference object that you use when you call push()
- that reference will be the root node under which the new randomly generated node name will be written.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论