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

125
Visualizações
Loop over json file to get seperate elements in my table

i'm working with BootstrapVue. I have a v-for loop which iterates over my json file and put the complete input in my <tr>-Tag.

Now I want to have an extra tr-Tag for each group in my json files - so I think I need to iterate over these groups first - but I dont know how to do that.

Code in my template:

<table>
  <tbody>
    <tr> <!-- I WANT TO ITERATE HERE OVER MY GROUPS TO SORT THEM -->
      <div v-for="(item, index) in json" :key="index">
        <b-form-input v-if="item.type" :type="item.type"></b-form-input>
      </div>
    </tr>
  </tbody>
</table>

my json:

[
    {
        "label": "Input 1",
        "type": "text",
        "group": "Test1"
    },
    {
        "label": "Input 2",
        "type": "text",
        "group": "Test2"
    },
    {
        "label": "Input 3",
        "type": "text",
        "group": "Test3"
    },
    {
        "label": "Input 4",
        "type": "number",
        "group": "Test1"
    }
]

This is what the code should look like, just for understanding, if it works:

<table>
  <tbody>
    <tr> 
       <b-form-input type="text"></b-form-input>
       <b-form-input type="number"></b-form-input>
    </tr>
    <tr>
       <b-form-input type="text"></b-form-input>
    </tr>
    <tr>
       <b-form-input type="text"></b-form-input>
    </tr>
  </tbody>
</table>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Putting v-for for tr

<table>
  <tbody>
    <tr v-for="(group, key) in getComputedJson" :key="key">
      <div v-for="(item, indexer) in group" :key="indexer">
        <b-form-input v-if="item.type" :type="item.type"></b-form-input>
     </div>
    </tr>
  </tbody>
</table>

and define a computed handler like

<script>
export default {
 computed: {
  getComputedJson() {
   const computedJson = {};
   this.json.forEach(item => {
    if(!computedJson[item.group]) {
     computedJson[item.group] = [];
     computedJson[item.group].push({label: item.label, type: item.type});
    } else {
    computedJson[item.group].push({label: item.label, type: item.type});
   }
  }
return computedJson;
}
</script>
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