JSFiddle - React, Tailwind, and code Playground
by psteele
HTML
<select id="country" data-bind="options: CountriesList ,optionsText: 'CountryName',value:selectedCountry, optionsCaption: 'Select Country..'"></select>
<input type='button' data-bind='click: showSelected' value='Show'></input>
JavaScript
var vm = {
CountriesList: [
{ CountryId: 123, CountryName: 'USA' },
{ CountryId: 456, CountryName: 'Canada' },
{ CountryId: 789, CountryName: 'France' },
],
selectedCountry: ko.observable(),
showSelected: function() {
alert(ko.toJSON(this.selectedCountry()));
}
};
ko.applyBindings(vm);