Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda