【问题标题】:Unable to process date from firebase in angular 6无法以角度 6 处理来自 Firebase 的日期
【发布时间】:2019-01-15 06:32:15
【问题描述】:
 this.qS = this.afDatabase.list('path', ref => {
    return ref.limitToLast(1000);
  }).snapshotChanges().map(changes => {
    return changes.map(c => ({ key1: c.payload.key,value1:c.payload.val() }));
  });
  this.qS.subscribe(values => {
    let count: number = Object.keys((values)).length;
    for(let i=0;i<count;i++){
           let const2:number=Object.keys(values[i].value1).length;  // is 3
           for(let j=0;j<const2;j++){
              console.log( values[i].value1[j]);//this line gives undefined why and How to get value from this?
            }
    }
  });

values[i].value1 =>[object 对象]

JSON.stringify(values[i].value1)=>
    {"-LJ2PhylTGjo1Li6QxP4":{"dtime":{"befor_":0,"dates":"04-Aug-2018","from_t":14,"fullDetails":"Between 2 PM to 6 PM on 7-08-2018","id":1,"mDay":"7","mMonth":"08","mYear":"2018","to_t":18,"weak":2},"lan":0,"lon":0},"-LJ2PtF3X9OaH-5Lv982":{"dtime":{"befor_":0,"dates":"04-Aug-2018","from_t":14,"fullDetails":"Between 2 PM to 6 PM on 7-08-2018","id":1,"mDay":"7","mMonth":"08","mYear":"2018","to_t":18,"weak":2},"lan":0,"lon":0},"-LJIQjbtU7Ryz-gUcxRF":{"dtime":{"befor_":0,"dates":"07-Aug-2018","from_t":14,"fullDetails":"Between 2 PM to 6 PM on 8-08-2018","id":1,"mDay":"8","mMonth":"08","mYear":"2018","timestampCreated":{"timestamp":1533629365655},"to_t":18,"weak":3},"lan":0,"lon":0}}

现在我们需要从上面的字符串中读取 fullDetails 日期。如何在打字稿中做到这一点?

【问题讨论】:

    标签: json angular typescript firebase firebase-realtime-database


    【解决方案1】:

    使用for in loop,因为它是一个对象:

    for (var j in values[i].value1) {
        console.log(values[i].value1[j].dtime.fullDetails)
    } 
    

    【讨论】:

    • 如何获得 -LJ2PhylTGjo1Li6QxP4 ?我试过 values[i].value1[j].key 但它是未定义的
    • 这里j-LJ2PhylTGjo1Li6QxP4
    猜你喜欢
    • 2019-03-01
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    相关资源
    最近更新 更多