Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
how to make a loop on a json file?

I have to handle a JSON file.

In JSON BLOCAGES -> BLOCAGE > I have to retrieve QTE and DTE.

Here is my file JSON here

My problem is that, I display QTE and DTE one time.

For now, I have this => enter image description here

I want to get this result => enter image description here

I'm missing the array elements [1] and [2], how could I add them from a loop?

Here is my method prepareDataForBlocage()

prepareDataForBlocage(response) {
    this.spinners.blockDetails = false;
    if (response['RETURNCODE'] == "OKK00") {


        let [variable1] = response['BLOCAGES']['BLOCAGE'];

        this.statusLine = {
            quantity: variable1['QTE'],
            update: variable1['DAT'],

        };

    }
}

My HTML

<table class="table table-striped">
   <tr style="background-color: #f8f9fa; font-weight: bold;">
      <td style="width: 13%;">Quantity</td>
      <td style="width: 13%;">Reason</td>
      <td style="width: 13%;">Date</td>
      <td style="width: 13%;">Référence</td>
   </tr>
   <tr  *ngIf="statusLine.quantity != 0" >
      <td>
         {{statusLine.quantity | number:'1.2-2' }}
      </td>
      <td></td>
      <td>
         {{statusLine.update | dateddmmyyyy }}
      </td>
      <td>
      </td>
   </tr>
</table>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I see 2 problems in your code

the first:

let [variable1] = response['BLOCAGES']['BLOCAGE'];
/// is the same as
let variable1 = response['BLOCAGES']['BLOCAGE'][0];
/// That means you only get the first element of your list

the second is that you do not loop over an array in your template.

You could try something like:

 this.myList = response['BLOCAGES']['BLOCAGE']
  .filter(blocage => blocage['QTE'] != 0)
  .map(blocage => ({
    quantity: blocage['QTE'],
    update: blocage['DAT'],
  }));
 <tr *ngFor="let elem of myList" >
      <td>
         {{elem.quantity | number:'1.2-2'  }}
      </td>
      <td></td>
      <td>
         {{elem.update | dateddmmyyyy  }}
      </td>
      <td>
      </td>
   </tr>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda