I just posted a message about a bug with select elements. While researching the bug, I realized that Knockout deletes all the options and re-adds them each time you make a selection in a select element. That’s because whenever you select an item, it changes the value of the variable bound to ‘value’ and triggers an update call on all the other bindings on the select, including ‘options’. This seems to be an inherent flaw in the design of Knockout that an update for one binding will update all the others even it’s not necessary.
I think to fix this would require each binding being set up as an individual dependent observable for each binding instead of the current method of having a single one for all bindings.
What do you think?
Thanks,
Michael
It would be nice if ko was a bit smarter about how it executes these
bindings, performance with a lot of select elements on screen can be
quite painful. I don't have the technical nous to make any guesses as
to how to do it though unfortunately.
This is useful here to separate the options and value bindings (value
cannot be in async because options needs to access it).
It can also be used, for example, if you have both template and
visible bindings on an element so that you can change the visibility
without rerunning the template.
Note that if your binding directly accesses an observable or calls a
function that accesses an observable, putting it async will not work
properly.
In this update, I added a button that deletes the selected item. With
the async options, the delete happens, but the value isn't updated. So
I also added a 'dummy' binding that accesses the array so that any
update to the array will update the value also.
-- Michael