knockoutjs how to get the selected option arrayObject

跟風遠走 提交于 2019-12-05 07:06:38

You don't have to add select event to the control. More efficient way is to subscribe on selectedCountry changes:

viewModel.selectedCountry.subscribe(function (data) {
        console.log(data)
    });

If you don't want any country is selected by default you have to add optionsCaption binding to the data-bind:

<select data-bind="options: availableCountries,
                       optionsText: 'countryName',
                       value: selectedCountry,
                       optionsCaption: 'Select...'"></select>

Here is working fiddle: http://jsfiddle.net/vyshniakov/tuMta/1/

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