flutter 更新所有具有特定项目的条目 - firebase-database
flutter update all entries that have a specific item - firebase-database
如何同时更新多个具有特定条目的数据库条目
在这种情况下,应更新“street”中条目为“8th St”的所有“posts”,项目“checked”应设置为“true”。
数据库结构:
+ posts
+ MPgslk7gshfasdjg
userName: Luke
street: 8th St
checked: false
...
+ sfdsflk7ghfdgrwj
userName: Joda
street: 1th St
checked: false
...
+ herjztwefhgrdhhr
userName: Vader
street: 8th St
checked: false
...
类似于:
final FirebaseDatabase _database = FirebaseDatabase.instance;
_database.ref().child("posts").orderByChild("street").equalTo("8th St").update({"checked": true});
谢谢
试试这个:
final _database = FirebaseDatabase.instance.reference();
await _database.child("posts").get().then(
(value) {
final data = Map<String, dynamic>.from(value.value);
data.forEach((key, value) {
if(value['street'] == "8th St"){
_database.child("posts/$key").update({"checked" : true});
}
});
}
);
试试这个:
final _database = FirebaseDatabase.instance.reference();
await _database.child("posts").orderByChild("street").equalTo("8th St").get().then(
(value) {
final data = Map<String, dynamic>.from(value.value);
data.forEach((key, value) {
if(value['street'] == "8th St"){
_database.child("posts/$key").update({"checked" : true});
}
});
}
);
如何同时更新多个具有特定条目的数据库条目
在这种情况下,应更新“street”中条目为“8th St”的所有“posts”,项目“checked”应设置为“true”。
数据库结构:
+ posts
+ MPgslk7gshfasdjg
userName: Luke
street: 8th St
checked: false
...
+ sfdsflk7ghfdgrwj
userName: Joda
street: 1th St
checked: false
...
+ herjztwefhgrdhhr
userName: Vader
street: 8th St
checked: false
...
类似于:
final FirebaseDatabase _database = FirebaseDatabase.instance;
_database.ref().child("posts").orderByChild("street").equalTo("8th St").update({"checked": true});
谢谢
试试这个:
final _database = FirebaseDatabase.instance.reference();
await _database.child("posts").get().then(
(value) {
final data = Map<String, dynamic>.from(value.value);
data.forEach((key, value) {
if(value['street'] == "8th St"){
_database.child("posts/$key").update({"checked" : true});
}
});
}
);
试试这个:
final _database = FirebaseDatabase.instance.reference();
await _database.child("posts").orderByChild("street").equalTo("8th St").get().then(
(value) {
final data = Map<String, dynamic>.from(value.value);
data.forEach((key, value) {
if(value['street'] == "8th St"){
_database.child("posts/$key").update({"checked" : true});
}
});
}
);