o [“ postmore”]不可迭代

时间:2019-09-04 06:02:11

标签: javascript angular

我想将created_time从CST转换为ISOString(ex:2019-02-22T17:43:05.000Z),所以我需要获得created_time。 但是我有个问题。当我使用for(let...of...){}时,出现错误

  

“ o.postmore不可迭代”。

如何固定代码以获得created_time并转换时间?

{
    "data": [
    {
        "text1": "123",
        "desc": "xyz",
        "postmore": [
        {
            "name": "haha",
            "created_time": "2018-08-22 18:30:01 CST+0800"
        },
        {
            "name": "gogo",
            "created_time": "2018-08-22 18:30:01 CST+0800" 
        }]
    },
    {
        "text1": "123",
        "desc": "hjk",
        "postmore": [
        {
            "name": "haha",
            "created_time": "2018-08-23 18:30:01 CST+0800"
        },
        {
            "name": "gogo",
            "created_time": "2018-08-23 18:30:01 CST+0800"
        }]
    }]
}


this.http.get(url).subscribe(res =>{

    this.testapi = res["data"];

    for (let o of this.testapi){

        o["text1"] = parseInt(o["text1"]);

        for(let os of o["postmore"]){
            os["created_time"] = new Date().toISOString();
            console.log(os["created_time"]);
        }

    };
)

0 个答案:

没有答案