svelte
svelte copied to clipboard
Two way bind with question mark
Describe the problem
I have input field with nested object properties, but sometimes the properties was null, i don't want to add variables to passing it.
Describe the proposed solution
Please allow,
https://svelte.dev/repl/5db9ddbb548042ad97398f47fb1a6ae0?version=3.59.1
Alternatives considered
i didn't know
Importance
would make my life easier
In the shared link the second record has location as null
.
I guess the ?
doesn't work in Svelte. Hence it can be made an empty object, like so: location: {}
As empty object:
https://svelte.dev/repl/8b62518f09464dfd986f726d9324c7fa?version=3.59.1
I hope this helps.
temporary i using this to convert null to object,
https://stackoverflow.com/questions/38078630/javascript-null-to-empty-object-properties
thanks
This isn't possible for the same reason that item.location?.name = value
isn't possible in JavaScript — you can't assign a property to a non-existent object, and you can't just create item.location
in order to assign that property. This would lead to ambiguity (what should happen when the input is updated?) and confusion.