Knockout.js: clear selection in select element

纵饮孤独 提交于 2019-12-06 03:13:07

One option would be to use the optionsCaption additional binding for the "not selected" value. It has to be set to something for it to be used, but you could set it to " ".

<select data-bind="optionsCaption: ' ', options: stations, value: selectedStation"></select>

Sample: http://jsfiddle.net/rniemeyer/Su8Zq/3/

Just add an 'optionsCaption', like this:

<select data-bind="options: stations, value: selectedStation, optionsCaption: '-- SELECT --'"></select>

Updated fiddle: http://jsfiddle.net/Su8Zq/2/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!