Test of valueAllowUnset
HTML
<p>
:
<select data-bind="options: countries,
optionsCaption: 'select',
value: selectedCountry,
valueAllowUnset: allowUnset
"></select>
</p>
<p>: <span data-bind="text: selectedCountry"></span> </p>
<label>
<input type="checkbox" data-bind="checked: allowUnset"/> valueAllowUnset
</label>
<br/>
<button data-bind="click: changeCountry"></button>
JavaScript
function ViewModel() {
var self = this;
self.countries = ['kl','s','sdf'];
self.selectedCountry = ko.observable('sdf');
self.allowUnset = ko.observable(false);
self.changeCountry = function() {
self.selectedCountry('d');
};
}
ko.applyBindings(new ViewModel());