Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:13:21+00:00 2026-06-03T21:13:21+00:00

Similar question as: Select element's initial value I’m having an issue setting the initial

  • 0

Similar question as: Select element's initial value

I’m having an issue setting the initial value of the select element. I basically have a list of seed data coming in from the server to populate the drop down list, and I want the selected value to represent what should be selected from the entity.

Because the data model’s selected value doesn’t equal the object reference in the seed data, nothing is selected.

Right now, I’m looping through each entity, finding the correct selected value, setting that equal to the seed data’s equivalent, then Knockout knows how to wire it up.

Is there a more elegant solution that this? I fiddled a simplified example with more details… http://jsfiddle.net/hbrYM/14/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:13:22+00:00Added an answer on June 3, 2026 at 9:13 pm

    As you correctly guessed the selectedValue reference doesn’t match so KO doesn’t select that item. The way to get this to work is to not save the complex object in the selected value and instead select the ID, as a primitive type equality can succeed and the correct value is selected.

    http://jsfiddle.net/VLTFB/3/

    You’ll need to use the optionsValue option on the options binding (if that makes sense 🙂

    <select data-bind="options: seedData,
                        optionsText: 'firstName',
                        optionsValue: 'ID',
                        value: data.selectedValue">
    

    EDIT

    As discussed you can reselect the correct item with a computed (untested).

    vm.currentlySelected = ko.computed(function () { 
       for (var i = 0; i < this.seedData().length; i += 1) {
           var data = this.seedData()[i];
           if (data.ID === this.selectedValue()) {
               return data;
           }
       }
       return null;
    }, vm);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two similar question, 1. I have a TabActivity, and when I select
I posted a similar question yesterday with the same code, I have rewritten and
Sorry I know similar question have been asked many times before but like most
Similar to my question at Using a sample list as a template for sampling
Similar question here but this is slightly different... I have two tables that I
I know there is a very similiar question ( JavaScript: How to select "Cancel"
Similar question as this one but for a Microsoft Environment. Email --> Exchange Server
Similar question , but for Oracle. Why would I not always want to choose
Similar question: Best Resources for Learning AS3 I am interested in learning AS3 and
A similar question discusses __construct , but I left it in my title for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.