如何尽快,因为它已经更新检索唯一的随机密钥?

问题描述 投票:0回答:1

我与火力的工作。但是,我是新来的火力点。我的应用程序有一个活动上载后,在这里是JSON结构。

post:{
  uid1:{
        -random1:{
                  text:hello,
                  uploader:John
                 },
         -random2:{
                  text:hello2334,
                  uploader:John
                 },
      },
  uid2:{
        -random3:{
                  text:Mornig,
                  uploader:Jack
                  },
      }

  }
likes:{
  uid1:{
        -random1:{
                  uid4:true,
                  uid5:true
                 },
        -random2:{
                  uid4:true,
                  uid3:true,
                 }

...}这里是我的示例代码时才能提交按钮,用户点击上传自己的帖子..

submit.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
                        post.push().setValue(textfield.getText());
                        /*I want to upload like node with the same random key but with different value. I don't know how to do it*/
                             }
                 });    

当用户点击后,我更新后的随机密钥,然后我想更新与相同的随机key.I等等不知道如何上传在同一时间与同一随机密钥到节点(仅UID和随机ID节点),因为我是一个菜鸟。我搜索了很多,但没有答案被发现。对不起,我的坏英语写作技巧...

firebase firebase-realtime-database
1个回答
2
投票

你写的数据之前,您可以拿到钥匙。您正在使用推送方法,这样会创建密钥,得到它,你需要使用推,还用之前的setValue

ref = root.child("post").child(uid);
key = ref.push().key //it could be getKey() depending on the sdk
ref.child(key).setValue(yourObject);
root.child("likes").child(ownerUid).child(key).child(uid).setValue(true)
© www.soinside.com 2019 - 2024. All rights reserved.