-
Look at the {#each questions as question}
<option value={question}>
{question.text}
</option>
{/each} MDN reminds us that
So try to manually code out the above markup in plain vanilla JS, say like so, readily pasteable into dev-tools: let val = { id: 1, text: "foo" };
let el = document.createElement('option');
el.value = val;
console.log(el.value, typeof el.value, el.value.text); Most recent Chromium version, you'll see the console print But clearly in Svelte it works, as the linked example showcases. Is Svelte's compilation logic special-casing Thanks for any insights that might demystify this =) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There is special logic because the Svelte stores the value in a separate property option = element("option");
option.__value = option_value_value = /*question*/ ctx[1];
set_input_value(option, option.__value); (This is also used for things like radio buttons and checkbox groups.) |
Beta Was this translation helpful? Give feedback.
There is special logic because the
value
as noted can only be a string.Svelte stores the value in a separate property
__value
on the DOM instance.The generated code in v4 looks like this:
(This is also used for things like radio buttons and checkbox groups.)