Use the for cycle correctly in Angular

0

Very good companions, the problem I have is that I do not know how to do a cycle for .

  

PURPOSE: Change the date format from timestamp to dd / mm / yyyy to JSON

I tried this

  this.dataTable.dataRows = response.data;
  for (let date of this.dataTable.dataRows){
    let date = moment(this.dataTable.dataRows.fecha.timestamp*1000).utc();
   this.dataTable.dataRows.fecha=date.format('YYYY-MM-DD');
}
 console.log(this.dataTable.dataRows);

The JSON is:

{
    "status": "success",
    "code": "200",
    "mensaje": "Todos los datos se han cargado correctamente",
    "data": [
        {
            "idCorrDoc": 1,
            "noResolucion": "15041-RES-CR-03925-2015",
            "serie": "15DS000F",
            "desde": 1,
            "hasta": 7000,
            "fecha": {
                "timezone": {
                    "name": "UTC",
                    "transitions": [
                        {
                            "ts": -9223372036854775808,
                            "time": "-292277022657-01-27T08:29:52+0000",
                            "offset": 0,
                            "isdst": false,
                            "abbr": "UTC"
                        }
                    ],
                    "location": {
                        "country_code": "??",
                        "latitude": 0,
                        "longitude": 0,
                        "comments": ""
                    }
                },
                "offset": 0,
                "timestamp": 1422835200
            },
            "status": true,
            "nomimprenta": "CREATIVA, S.A. DE C.V.",
            "nitimprenta": "0614-231092-107-7",
            "nrcimprenta": "72018-6",
        }           
    ]
}
    
asked by jeasomoza 03.02.2018 в 18:57
source

1 answer

0

The problem is that you are not assigning the date to any variable.

  this.dataTable.dataRows = response.data;
      for (let i=0; i < this.dataTable.dataRows.length; i++){
        let date = moment(this.dataTable.dataRows[i].fecha.timestamp*1000).utc();
       this.dataTable.dataRows[i].fecha=date.format('YYYY-MM-DD');
    }
  • The way you declare the cycle, the context of the arrangement is lost because you resign it.
answered by 16.02.2018 в 01:06