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

231
Vistas
Svelte set bind:value from #each Key

I am trying to bind values to a Each Value:

For example:

JS:

let test = ""
let headers = [
    {
      title: "test",
      connected: test,
    }
]

const setPage = () => {
    console.log(test);
  };

HTML:

{#each headers as header}
<input
 type="text"
 placeholder={header.title}
 bind:value={header.connected}
 on:change={() => setPage(1)}
/>
{/each}

The Header Title works as expected but the binding does not work. Is there any way that i can use it like this?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

In the beginning the start value will be set to the value of test - since it's an empty string in your case, that can't be seen.

After the value of the input is changed the reactive log shows that the value of header.connected changes accordingly.
So the binding basically does work. Not sure if you expected test to change as well? How should everything then behave if there was more than one header object?

REPL

<script>
    let test = ""
    let headers = [
        {
            title: "header1",
            connected: test,
        },
        {
            title: "header2",
            connected: test,
        }
    ]

    function updateTest(event) {
        test = event.target.value
    }

    $: console.log('headers', headers)
</script>

<p>
    test: {test}
</p>

{#each headers as header}
<input
             type="text"
             placeholder={header.title}
             bind:value={header.connected}
             on:input={updateTest}
             />
{/each}
about 4 years ago · Santiago Trujillo 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