gpt4 book ai didi

火力地堡数据库 : how can I change value of list item?

转载 作者:IT王子 更新时间:2023-10-29 07:03:29 30 4
gpt4 key购买 nike

我的数据库中有这样的结构:

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com