Im rewriting some standard jquery dynamic select menus into knockout. In pain jquery it adds options to a select menu with this:
$.each(data.DropDownOptions, function() {
if (this.ID != undefined) {
$(".SelectDDL").append($("<option value='" + this.ID + "'></option>").html(this.Option));
}
});
the options frequently have " symbols in it which at the point "this.Option" appears as " because its JSON. But in the actual dropdown they appear as " (the actual symbol).
I rewrote it into knockout using practically the same logic and using a template like this.
function CarOptionMenu(data) {
return {
CarOptions: ko.observableArray(data),
selection: ko.observable()
}
}
function KnockoutModel() {
var self = this;
self.menuWrapper = ko.observableArray([]);
}
var list = new KnockoutModel();
ko.applyBindings(list );
and in place of the above jQuery function it adds options like this:
list.menuWrapper.push(new CarOptionMenu(data.DropDownOptions));
Which works fine except the " remains " and never gets parsed into the " symbol. Any idea on how to fix that?
--EDIT-- Here is the select element and template:
<script type="text/html" id="car-option-menu-template">
<select data-bind='options:CarOptions, optionsText:"Option",optionsValue:"ID",value: selection' style="width: 100% !important; margin-top: 5px;"></select>
</script>
<div data-bind="template: { name: 'car-option-menu-template', foreach: menuWrapper}"></div>