- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我的数据库中有这样的结构:
User 1
+- items
+- 1
| |- question: some question
| |- answer: some answer
|
+- 2
|- question: another question
我想为第二项添加答案,但我没有 ID。我正在尝试获取元素,它返回了
[null, {answer: some answer, question: some question}, {question: another question}]
但如果没有 answer
字段,我无法获得所需的项目,也无法获得他们的 ID。
我尝试使用 equalTo
,但没有用。
// attempt 1
Query child = _databaseReference.child(item._user).child(db_items).equalTo(null, key: db_answer);
child.reference().once().then((DataSnapshot snapshot) {
print('snapshot: ${snapshot.value}');
});
// attempt 2
Query child = _databaseReference.child(item._user).child(db_items).equalTo(null, key: db_answer);
child.reference().child(db_question).once().then((DataSnapshot snapshot) {
print('snapshot: ${snapshot.value}');
});
第一次尝试返回与我上面写的相同的输出,第二次返回 null
那么,有人知道如何将 answer
字段添加到第二个问题吗?
附言我使用 Flutter,但我认为这对这个问题意义不大。
最佳答案
所以基本上您是在尝试将“答案”添加到您的第二个项目。我会这样做:首先是事先知道 key ,这样我就可以在第二项中插入一个子节点。这样我就可以写类似的东西:myDBReference.child("items").child("key_known_beforehand").child("answer").setValue("this is the ansewr");
或者万一我不知道 key ,这似乎是这里的问题:我会使用 Firebase 查询。就像是..myDBReference.child("items").orderByValue().startAt(starting_point_of_child_item).endAt(ending_point_of_child_item).child这个查询会给我所需的节点,我会在那里设置值。
”
Using startAt(), endAt(), and equalTo() allows you to choose arbitrary starting and ending points for your queries
要过滤数据,您可以在构造查询时将任何 limit 或 range 方法与 order-by 方法结合使用。
Unlike the order-by methods, you can combine multiple limit or range functions. For example, you can combine the startAt() and endAt() methods to limit the results to a specified range of values.
”
关于火力地堡数据库 : how can I change value of list item?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56006906/
我是一名优秀的程序员,十分优秀!