如何从firebase数据库中删除最后一个节点?
这是json:
{"Top":{
"-LEdsuTpH4RKwjweqTNG" : {
"conversionStatus" : 0,
"dateStamp" : "6/10/2018"
},
"-LEdz-O3fQECgKTsYu1U" : {
"conversionStatus" : 0,
"dateStamp" : "6/10/2018"
},
"-LEdz7gymhoCQTQVWrtz" : {
"conversionStatus" : 0,
"dateStamp" : "6/10/2018"
}
}
}
我想删除最后一个节点==>
"-LEdz7gymhoCQTQVWrtz" : {
"conversionStatus" : 0,
"dateStamp" : "6/10/2018"
}
答案 0 :(得分:6)
这就是我做到的:
Firebase.instance.reference()
.child("Top").limitToLast(1).once()
.then((DataSnapshot snapshot){
Map map = snapshot.value;
snapShotKeyToDel = map.keys.toList()[0].toString();
}
Firebase.instance.reference()
.child("Top").child(snapShotKeyToDel).remove();