Javascript 如何在firestore字段中的数组字段内循环并检索具有真值的最后一个结果?

Javascript 如何在firestore字段中的数组字段内循环并检索具有真值的最后一个结果?,javascript,firebase,flutter,dart,google-cloud-firestore,Javascript,Firebase,Flutter,Dart,Google Cloud Firestore,参考此图像,模块0已锁定为false,模块1已锁定为true,因此我应该收到名称“What is spirituality” 我想检索上一个模块锁定为false的下一个模块的名称。您可以获取完整列表并检查您的条件 DocumentSnapshot docSnapshot = Firestore.instance.collection("collectionName").document("docId").get(); //gets the data of

参考此图像,模块0已锁定为false,模块1已锁定为true,因此我应该收到名称“What is spirituality”


我想检索上一个模块锁定为false的下一个模块的名称。

您可以获取完整列表并检查您的条件

DocumentSnapshot docSnapshot = Firestore.instance.collection("collectionName").document("docId").get(); //gets the data of your document => replace the collectionName and docId

bool previousIsLockedValue = false; //this keeps track of the previous module isLoked property value and the initial value is false so if the first module's isLocked is true then name will be retrieved
String nameOfModule;

List<dynamic> modules = docSnapshot.data["modules"] //gets the modules list from the document data

for (module in modules){
    if(module["isLocked"] == true && previousIsLockedValue == false){
       nameOfModule = module["name"]; 
       //assigns the module name if the previous isLocked value is false and this 
       //module isLocked value is true

       //Do something with the name ...
    }
    previousIsLockedValue = module["isLocked"];
}


DocumentSnapshot docSnapshot=Firestore.instance.collection(“collectionName”).document(“docId”).get()//获取文档的数据=>替换collectionName和docId
bool-previousIsLockedValue=false//这将跟踪上一个模块的isLocked属性值,初始值为false,因此如果第一个模块的isLocked为true,则将检索名称
模块的字符串名称;
List modules=docSnapshot.data[“modules”]//从文档数据获取模块列表
用于(模块中的模块){
if(模块[“isLocked”]==true&&previousIsLockedValue==false){
模块名称=模块[“名称”];
//如果上一个isLocked值为false且此值为
//模块isLocked值为true
//用这个名字做点什么。。。
}
previousIsLockedValue=模块[“isLocked”];
}
您可以将
previousIsLockedValue
的初始值更改为true,以便在其IsLocked属性为true时不会获得第一个模块名