【问题标题】:how to load the data from a firestore 'get' into variables?如何将数据从 Firestore 'get' 加载到变量中?
【发布时间】:2018-06-02 22:07:10
【问题描述】:

我正在升级到 Angular v5 和 firestore,我在从 firestore 数据中提取字段时遇到了很多问题。

我不想使用 angularfire2,因为我在 Angular 4 发布时遇到了问题。

大约 10 天前,我花了很长时间研究如何从快照中获取数据。最后我得到了下面的代码来做到这一点。不幸的是“doc.data()['languageName'];”不适用于“获取”。

 querySnapshot.forEach(function (doc) {
    let name = doc.data()['languageName']; 
    lang.push(name);
  });
});

在为此工作了一整天后,我决定寻求帮助。我最近的尝试如下。

firebase.auth().signInWithEmailAndPassword(email, password)
  .then(staff => {
    if (staff.emailVerified) {
      this.result = this.db.collection("staff").doc(staff.uid).get()
       .then(function(staffDb) {                 // staff.uid works
         if (staffDb.exists) {      // <--  Works to here
           this.sid = staffDb.data.sid;          // nor staff.sid 
           this.staff2memoryService.set(staffDb.data());
           this.staff = this.db.collection("staff").
                                 doc(this.sid).get()
           .then(result => {
              if (this.sid) {
                this.staff2memoryService.set(result);
              } else {
                console.log('Not exist');
              }  

当我执行 console.log 时,我想要的所有数据都在那里,但我无法得到它。 firebase 文档展示了如何使用 console.log 访问字段,但这无济于事,因为 console.log 似乎会自动提取/映射字段。

【问题讨论】:

    标签: javascript angular google-cloud-firestore


    【解决方案1】:

    我昨天尝试使用“this.data”但没有成功,但以下工作。

        if (staffDb.exists) {  
          var data = staffDb.data();
          var eid = data.eid;
    

    有时最好在一个问题上睡觉,昨天几个小时今天几分钟。我渐渐老了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 2019-04-25
      • 2013-10-31
      • 1970-01-01
      • 2014-07-22
      • 2016-02-11
      • 1970-01-01
      相关资源
      最近更新 更多