无法以角度 6 处理来自 Firebase 的日期
Posted
技术标签:
【中文标题】无法以角度 6 处理来自 Firebase 的日期【英文标题】:Unable to process date from firebase in angular 6 【发布时间】: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 日期。如何在打字稿中做到这一点?
【问题讨论】:
【参考方案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
以上是关于无法以角度 6 处理来自 Firebase 的日期的主要内容,如果未能解决你的问题,请参考以下文章