javascript - Show white spaces in select combobox that is filled with knockout js binding -


i able fill html select element knockout binding. of option texts include white spaces , i'd show them in dropdown.

in pure html can accomplished using   instead of simple white spaces, that's not working knockout binding:

working example

html:

knockout select: <select data-bind="options: entries" style="width: 150px"></select> <br> standard select: <select style="width: 150px">     <option>&nbsp;&nbsp;entry 1</option>     <option>&nbsp;&nbsp;&nbsp;&nbsp;entry 2</option> </select> 

javascript:

var viewmodel = function() {     entries = ko.observablearray([         '&nbsp;&nbsp;entry 1',         '&nbsp;&nbsp;&nbsp;&nbsp;entry 2'     ]); };  var vm = new viewmodel(); ko.applybindings(vm); 

hope can me this!

thanks

you can use regular foreach instead of options can set html content html binding on option elements:

<select data-bind="foreach: entries" style="width: 150px">     <option data-bind="html: $data"></option> </select> 

demo jsfiddle.


Comments