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

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

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 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