Extract certain data from a Json array

Asked

Viewed 471 times

0

I have taken a Json from an API that returns this result:

[
  {
    "marca_id": 4,
    "modelo_id": 2708,
    "versao_id": 65344,
    "cor": "Azul",
    "opcionais": [
      {
        "opcional_id": 6,
        "opcional_nome": "Airbags"
      },
      {
        "opcional_id": 10,
        "opcional_nome": "Freios ABS"
      },
      {
        "opcional_id": 18,
        "opcional_nome": "Ar Condicionado"
      },
      {
        "opcional_id": 22,
        "opcional_nome": "Direção Hidráulica"
      },
      {
        "opcional_id": 19,
        "opcional_nome": "Bancos de Couro"
      }
    ],
    "valor": "40000,00",
    "kilometragem": 97437,
    "imagens": [
      "imagem"
    ],
    "thumbs": [
      "miniatura.jpg"
    ],
    "url_ficha_registro": "0001",
    "loja": "4555"
  }
]

How do I access to print on an ng-repeat all items in the "optional" field? Because if I print type {{x.opcional}} or {{x.opcional[3]}} it returns me the array, logical. It may seem a somewhat silly question but I’m really banging my head with it, having an ng-repeat inside another?

2 answers

1


Solved. In case anyone needs this below:

<div ng-repeat="dado in x.opcionais">
  {{ dado.opcional_nome }} 
</div>

0

Thus:

<tr>
   <td ng-repeat="x.opcionais as dado">
     {{dado.opcional_id}}
     {{dado.opcional_nome}}
   </td>
</tr>
  • Hello Ivan, unfortunately it didn’t work. It prints in the source code the following: <!-- ngRepeat: x.opcional as dice --> Some other idea?

  • Thanks van, I found the answer now! Brawl!

  • Dude, I traveled, that’s right, in case it was "given in x.opcional" :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.