Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout bind optional fields

I'm trying to bind a JSON containing optional fields using knockout js. The problem is I keep getting this error:

Unable to process binding "value: function..."

And I can't add the missing fields as I need them to remain missing (the missing fields are taken from a "parent" JSON)

Is there any option to tell knockout js to ignore those fields and only add them if a user types anything in the field?

like image 991
Tals Avatar asked Nov 07 '25 21:11

Tals


1 Answers

You can bind to a non-existent view-model property if you use the property syntax, like $data.property.

<input type="text" data-bind="value: $data.key">

https://jsfiddle.net/hrfq3wdh/2/

like image 199
Michael Best Avatar answered Nov 11 '25 01:11

Michael Best



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!