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

256
Vistas
Convert string to boolean for checkbox

I use v-model to display checked/unchecked checkboxes:

<template v-for="(item, index) in myFields">
  <v-checkbox
     v-model="myArray[item.code]"
     :label="item.name"       
   />
</template>

It works fine when I get true or false values from API. But now I get strings: "true" or "false" and my checkbox is always checked. If I change the code on:

v-model="Boolean(myArray[item.code])"

I got the error:

'v-model' directives require the attribute value which is valid as LHS

How can I solve this problem?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Trying Boolean(myArray[item.code]) won’t work anyway because the string 'false' is true. So Boolean('false') return true.

Instead you should do myArray[item.code] !== 'false'
'false' will return false and every other string than false will return true

EDIT: You need to change myArray to an array of boolean like so

myArray.map((element) => element !== 'false')

Then this code will work

<template v-for="(item, index) in myFields">
  <v-checkbox
     v-model="myArray[item.code]"
     :label="item.name"       
   />
</template>
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