<p>
Select a country:
<select data-bind="options: countries,
optionsCaption: 'Choose one...',
value: selectedCountry,
valueAllowUnset: true"></select>
</p>
<script type="text/javascript">
var viewModel = {
countries: ['Japan', 'Bolivia', 'New Zealand'],
selectedCountry: ko.observable('Latvia')
};
</script>
在这段代码中,我们将valueAllowUnset设置为true,此时我们将value设置为“Lativia”时,列表中不存在此项,那么将会把selectedCountry设置为undefined,界面显示“Choose one…”项。