Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Multi select does not work when binding options from REST call

2930948Apr 5 2016 — edited Apr 12 2016

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

This post has been answered by Jim.Marion-Oracle on Apr 6 2016
Jump to Answer
Comments
Post Details
Added on Apr 5 2016
5 comments
3,307 views