Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!