knockoutjs valueAllowUnset 属性

来源:互联网 发布:比特币是网络传销吗 编辑:程序博客网 时间:2024/05/29 19:00
<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…”项。
0 0