问题
I have an address form for multiple addresses.
http://jsfiddle.net/VAs5r/6/
When the form is loaded, the addresses object has a value Active:false that is bind to the enable property to all the input fields in order to block any entry. Then a button named "new address" change the Active property to true in order to enable all the inputs and let the user to enter information.
Is working but the problem is that is not refreshing the fields until you change the select option and then return again to the current address type.
Is there any work around to this?
Thanks.
回答1:
Here is your fiddle, updated and working.
The problem you were having is that this is not a valid way to set observable values:
self.selectedAddress().active=true;
In knockout, observables are functions, and are set by passing new values to them as parameters, like this:
self.selectedAddress().active(true);
When you set observables the way you were doing it, their "observability" is overwritten, and they become standard objects. When this happens, the UI is not notified of their updates.
来源:https://stackoverflow.com/questions/11365664/knockout-force-select-update-binding