0

my dropdown list is returning [object][object] instead of the value. I am getting the values from an sql table. Any assistance would be great. Thanks in advance.

viewmodel

 vm.addObservables('selected');
vm.addObservableArrays('list');

_Integration.GetAll('sqlTable').then(function(vals){
        vm.list(vals);

});

html

<select id="dropDown" name="dropDown" 
    data-bind='options: list, 
               value: selected, 
               optionsCaption: "Choose...", 
               autoSave: true'>

</select>

1 Answer 1

2

You're binding the dropdown to an array of objects without saying how to interpret those objects. Add the data-bind optionsText: 'fieldName' where fieldName is the name of the property on your object that you'd like to display.

http://knockoutjs.com/documentation/options-binding.html

sample:

<select data-bind="options: availableCountries,
                   optionsText: 'countryName',
                   value: selectedCountry,
                   optionsCaption: 'Choose...'"></select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.