Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flatter/Firestore-如何接触Firebase上的嵌套元素?_Firebase_Flutter_Google Cloud Firestore_Nested Lists - Fatal编程技术网

Flatter/Firestore-如何接触Firebase上的嵌套元素?

Flatter/Firestore-如何接触Firebase上的嵌套元素?,firebase,flutter,google-cloud-firestore,nested-lists,Firebase,Flutter,Google Cloud Firestore,Nested Lists,我正在开发一个英语词汇学习应用程序。 我创建了一些数据类来创建不同的对象: 以下是其中两个: class CarnetWords { int? iD; int? wrong; int? right; double? mastery; CarnetWords( {@required this.iD, @required this.wrong, @required this.right, @required this.mastery

我正在开发一个英语词汇学习应用程序。
我创建了一些数据类来创建不同的对象: 以下是其中两个:

class CarnetWords {
  int? iD;
  int? wrong;
  int? right;
  double? mastery;
  CarnetWords(
      {@required this.iD,
      @required this.wrong,
      @required this.right,
      @required this.mastery});
}

class VocList {
  String? ref;
  String? titre;
  DateTime? creation;
  DateTime? modification;
  DateTime? firstSession;
  DateTime? latestSession;
  double? mastery;
  List<CarnetWords>? wordId;
  VocList(
      {@required this.ref,
      @required this.titre,
      @required this.creation,
      @required this.modification,
      @required this.firstSession,
      @required this.latestSession,
      @required this.mastery,
      @required this.wordId});
}

可能是这样的,首先迭代列表的iten,然后将列表添加到对象中

await _fireStore3.get().then((QuerySnapshot querySnapshot) {
  querySnapshot.docs.forEach((doc) {
    List<CarnetWords> carnetWords = [];
    Map mots = doc['mots'];
    
    mots.forEach((index, value){
      carnetWords.add(CarnetWords(id: value.id, wrong: value.wrong, right: value.wrong, mastery: value.mastery.toDouble()));
    });
    
    _carnetVoc2.add(
      VocList(
        ref: doc['ref'],
        titre: doc['titre'],
        creation: doc['dateCreation'].toDate(),
        modification: doc['dateModification'].toDate(),
        firstSession: doc['firstSession'].toDate(),
        latestSession: doc['latestSession'].toDate(),
        mastery: doc['mastery'].toDouble(),
        wordId: carnetWords,
      ),
    );
  });
wait\u fireStore3.get().then((QuerySnapshot QuerySnapshot){
querySnapshot.docs.forEach((doc){
列出carnetWords=[];
Map mots=doc['mots'];
交通费(指数、价值){
添加(carnetWords(id:value.id,error:value.error,right:value.error,mastery:value.mastery.toDouble());
});
_carnetVoc2.add(
声音列表(
参考:文件['ref'],
标题:doc[“titre”],
创建:doc['dateCreation'].toDate(),
修改:doc['dateModification'].toDate(),
firstSession:doc['firstSession'].toDate(),
latestSession:doc['latestSession'].toDate(),
精通:doc['mastery'].toDouble(),
carnetWords,
),
);
});

}可能是这样的,首先迭代列表的iten,然后将列表添加到对象中

await _fireStore3.get().then((QuerySnapshot querySnapshot) {
  querySnapshot.docs.forEach((doc) {
    List<CarnetWords> carnetWords = [];
    Map mots = doc['mots'];
    
    mots.forEach((index, value){
      carnetWords.add(CarnetWords(id: value.id, wrong: value.wrong, right: value.wrong, mastery: value.mastery.toDouble()));
    });
    
    _carnetVoc2.add(
      VocList(
        ref: doc['ref'],
        titre: doc['titre'],
        creation: doc['dateCreation'].toDate(),
        modification: doc['dateModification'].toDate(),
        firstSession: doc['firstSession'].toDate(),
        latestSession: doc['latestSession'].toDate(),
        mastery: doc['mastery'].toDouble(),
        wordId: carnetWords,
      ),
    );
  });
wait\u fireStore3.get().then((QuerySnapshot QuerySnapshot){
querySnapshot.docs.forEach((doc){
列出carnetWords=[];
Map mots=doc['mots'];
交通费(指数、价值){
添加(carnetWords(id:value.id,error:value.error,right:value.error,mastery:value.mastery.toDouble());
});
_carnetVoc2.add(
声音列表(
参考:文件['ref'],
标题:doc[“titre”],
创建:doc['dateCreation'].toDate(),
修改:doc['dateModification'].toDate(),
firstSession:doc['firstSession'].toDate(),
latestSession:doc['latestSession'].toDate(),
精通:doc['mastery'].toDouble(),
carnetWords,
),
);
});

}

我设法解决了这样的问题:

await _fireStore3.get().then((QuerySnapshot querySnapshot) {
      querySnapshot.docs.forEach((doc) {
        List<dynamic> mots = doc['mots'].toList();
        List<CarnetWords> wordId = [];
        for (Map indivMots in mots) {
          wordId.add(
            CarnetWords(
                iD: indivMots['id'],
                wrong: indivMots['wrong'],
                right: indivMots['right'],
                mastery: indivMots['mastery']),
          );
        }
wait\u fireStore3.get().then((QuerySnapshot QuerySnapshot){
querySnapshot.docs.forEach((doc){
List mots=doc['mots'].toList();
List wordId=[];
用于(在mots中映射indivMots){
wordId.add(
卡通卡(
iD:indivMots['iD'],
错误:indivMots[“错误”],
右:indivMots[“右”],
掌握:独立的[掌握],
);
}

我设法解决了这样的问题:

await _fireStore3.get().then((QuerySnapshot querySnapshot) {
      querySnapshot.docs.forEach((doc) {
        List<dynamic> mots = doc['mots'].toList();
        List<CarnetWords> wordId = [];
        for (Map indivMots in mots) {
          wordId.add(
            CarnetWords(
                iD: indivMots['id'],
                wrong: indivMots['wrong'],
                right: indivMots['right'],
                mastery: indivMots['mastery']),
          );
        }
wait\u fireStore3.get().then((QuerySnapshot QuerySnapshot){
querySnapshot.docs.forEach((doc){
List mots=doc['mots'].toList();
List wordId=[];
用于(在mots中映射indivMots){
wordId.add(
卡通卡(
iD:indivMots['iD'],
错误:indivMots[“错误”],
右:indivMots[“右”],
掌握:独立的[掌握],
);
}

我想你忘了阵列ID,你的“MOT”如果要在数组中存储地图,您还必须传递要从中获取数据的数组的索引;我无法告诉您如何准确访问它,因为我也是firestore的noob,但这应该是您面临的问题是,感觉那里应该有某种附加循环……但我不知道如何实现它这里…看这里我想你忘了阵列ID,你的“MOT”如果要在数组中存储地图,您还必须传递要从中获取数据的数组的索引;我无法告诉您如何准确访问它,因为我也是firestore的noob,但这应该是您面临的问题是,感觉那里应该有某种附加循环……但我不知道如何实现它好了…看这里谢谢你的帮助。我还没有尝试过,但我相信它会起作用。我设法用循环解决了这个问题。请参阅上面的答案。我相信你使用forEach方法的代码也会这样做。我总是很难用forEach方法编写代码。例如,在你给我的代码中:什么是“索引”?什么是索引“值”?所以,下面的解决方案和我在这里做的一样,索引(在mox树中,索引是每个树中的数字0、1、2都有值),而值就是其中的内容,就像下面的代码中称为indivMots的内容一样。很高兴你能工作。再次感谢你的建议。它看起来比我的更简洁:)谢谢你的帮助。我还没有尝试过,但我相信它会起作用。我使用循环解决了这个问题。请参阅上面的答案。我相信使用forEach方法的代码也会这样做。使用forEach方法编写代码总是有困难。例如,在你给我的代码中:什么是“索引”?什么是“值”“?因此,下面的解决方案与我在这里做的相同,索引(在mox树中,索引是数字0、1、2,每个索引中都有值),值是其中的内容,就像下面的代码中称为indivMots的内容一样。很高兴您能使用它。再次感谢您的建议。它看起来比我的更简洁:)