将对象存储在firebase中(应用程序发明者2)

时间:2017-08-17 03:15:45

标签: android firebase indexing firebase-realtime-database app-inventor

我正在从应用程序发明者编写一个应用程序,这是一个笔记本应用程序

在应用程序中有两个功能

  • 查看备注

  • 添加注释

添加注释功能中,我不知道如何将对象上传到firebase。我想要的是创建一个id" 1" " 2"自动

对象是这样的:

the object is something like this

我正在尝试但不起作用(firebase赢了并将它拆分为对象,但json:

What I am trying but not work (firebase won't split it in object but a json)

1 个答案:

答案 0 :(得分:0)

您应该使用push()方法代替" 1"," 2" push方法为您生成一个唯一的键实际上它正是您想要的。在你的情况下有一个问题;如果两个用户想要同时在其笔记添加的同一位置添加注释?因此,通过使用唯一的子键,多个客户端可以同时将子节点添加到同一位置,而不必担心写入冲突。

您可以使用getKey()方法找到id。 Look for usage of push() and getKey() methods.

{ "notes": { "-KzY........": { "content": "This is my first note", "title": "Hello World!" }, "-KzT........":: { "content": "This is my second note", "title": "Hello Firebase!" } } }