Hello,
I am having trouble with multi select. The problem is when I get the data for the options from the REST call then upon selecting the option it shows it's value in the select and not the label.
Here is some example code for the problem (for the simplicity of the example let's assume that the view model is properly bind to the select element, $ variable is jQuery object, url is variable containing the endpoint url of the server, the REST call is successful and the returned data is in following format:
[{value: '1', label:'Label for item 1'}, {value: '2', label: 'Label for item 2'}, {value: '3', label: 'Label for item 3'}]
):
HTML snippet:
<label for="select">Select with options array</label>
<select id="select" data-bind="ojComponent: {component: 'ojSelect', options: browsers, multiple: true,
rootAttributes: {style:'max-width:20em'}}">
</select>
and Javascript
function selectModel () {
var self = this;
this.browsers = ko.observableArray([]);
$.getJSON(url, function(data) {
self.browsers(data);
});
}
The problem is that in this example the options in the select are correct - Label for item 1, Label for item 2, .... But when one of them is selected then inside the select box it's value is shown eg. '1' instead of the label. This is problem only with multi select and when setting options in the callback from the REST call, single select works fine.
Any ideas how to solve this?
Thank you
Vasek Stebra