我的 firebase 實時資料庫中有這樣的持續資料。我想獲取值大于 75 的鍵,它們的值和省值。
{
"allboxes": {
"box00001": {
"boxes": {
"Electronic Box": 80,
"Glass Box": 25,
"Metal Box": 78,
"Oil Box": 90,
"Paper Box": 77,
"Plastic Box": 18
},
"info": {
"Id": "00001",
"Province": "Ke?i?ren"
}
},
"box00002": {
"boxes": {
"Electronic Box": 95,
"Glass Box": 86,
"Metal Box": 45,
"Oil Box": 79,
"Paper Box": 98,
"Plastic Box": 18
},
"info": {
"Id": "00002",
"Province": "Etimesgut"
}
},
"box00003": {
"boxes": {
"Electronic Box": 55,
"Glass Box": 91,
"Metal Box": 79,
"Oil Box": 65,
"Paper Box": 50,
"Plastic Box": 100
},
"info": {
"Id": "00003",
"Province": "?ankaya"
}
}
}
}
我將在這樣的 Gridview.builder 中使用它;
GridView.builder(
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 220,
crossAxisCount: 2,
crossAxisSpacing: 15,
),
itemCount: boxesValuesList!.length,
itemBuilder: (context, index) => OpenedBoxesGrid(
boxesValuesList![index].toString(),
boxesKeysList![index],
provinceValuesList![index],
),
)
我試過這個;
final greaterThan75ValueTaskRef = FirebaseDatabase.instance
.ref('allboxes')
.orderByChild('boxes/Oil Box')
.startAt(75);
它在列印函式中回傳它。
I/flutter(6345):[{盒子:{玻璃盒:86,塑料盒:18,電子盒:95,金屬盒:45,油盒:79,紙盒:98},資訊:{Id:00002,省份:Etimesgut}},{盒子:{玻璃盒:25,塑料盒:18,電子盒:80,金屬盒:78,油盒:90,紙盒:77},資訊:{Id:00001,省份: Ke?i?ren}}]
但正如我提到的,我想在一個串列中獲取鍵,在另一個串列中獲取它們的值,在另一個串列中獲取它們的省值。我怎樣才能做到這一點?我想創建三個串列,其中每個元素的有序等效項是這樣的。
【電子盒、金屬盒、油盒、紙盒、電子盒、玻璃盒、油盒、紙盒、玻璃盒、金屬盒、塑料盒】
[80, 78, 90, 77, 95, 86, 79, 98, 91, 79, 100]
[Ke?i?ren,Ke?i?ren,Ke?i?ren,Ke?i?ren,Etimesgut,Etimesgut,Etimesgut,Etimesgut,?ankaya,?ankaya,?ankaya]
uj5u.com熱心網友回復:
當您從 Firebase 實時資料庫中讀取資料時,您會獲得一個DataSnapshot物件,其中包含您讀取的路徑中的所有資料。
要獲取快照的鍵,請呼叫其key屬性。
要僅獲取快照下的特定分支,請使用其child()方法。因此,例如(假設這boxesValuesList是DataSnapshot您共享的查詢的結果),要獲取構建器中框的快照,您可以使用boxesValuesList![index].child("boxes").
這可以深入多個級別,因此再次假設這boxesValuesList是您共享的查詢的結果,您可以使用:或簡寫符號:DataSnapshot獲得 Oilbox 的值。boxesValuesList![index].child("boxes").child("Oil Box").getValue()boxesValuesList![index].child("boxes/Oil Box").getValue()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/481045.html
標籤:火力基地 扑 镖 firebase-实时数据库
