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 9102985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:31:12+00:00 2026-06-17T01:31:12+00:00

I have defined my select as below <select id=selProductType data-bind=options: productType , value: editProductType

  • 0

I have defined my select as below

<select id="selProductType" data-bind="options: productType , value: editProductType , optionsText: 'Name'" />

Below is my code to fill the select in my view model

 // Loading combobox with Product Types
    $.getJSON("../RestService/Product/AllProductTypes",
      function (allData) {
          var mappedProductType = $.map(allData, function (item) {
              console.log(item.Id + ' ' + item.Name);
              return new productType(item);
          });
          self.productType(mappedProductType);

      });

When i initialise page i want to set default value to select. So i tried below

self.editProductType(4);

But it gives me TypeErrror saying object 4 has no method Id.

How to go about it. I have also gone through similar post in stackoverflow but no luck.

Knockout JS binding initial/default value of dropdown (select) list

  • 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-17T01:31:13+00:00Added an answer on June 17, 2026 at 1:31 am

    If you don’t specify the :

    optionsValue: 'Id'
    

    in data-bind, the binding value in this case must be an object in productType array.

    You can select the default object:

    self.editProductType(self.productType()[2]);
    

    What is optionsValue?

    Similar to optionsText, you can also pass an additional parameter called optionsValue to specify which of the objects’ properties should be used to set the value attribute on the elements that KO generates. You can also specify a JavaScript function to determine this value. This function will receive the selected item as its only argument and should return a string to use for the element’s value attribute.

    Typically you’d only want to use optionsValue as a way of ensuring that KO can correctly retain selection when you update the set of available options. For example, if you’re repeatedly getting a list of “car” objects via Ajax calls and want to ensure that the selected car is preserved, you might need to set optionsValue to “carId” or whatever unique identifier each “car” object has, otherwise KO won’t necessarily know which of the previous “car” objects corresponds to which of the new ones.

    read more at: http://knockoutjs.com/documentation/options-binding.html

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

Sidebar

Related Questions

I have a select box defined as shown below. I want to print out
I have a series of select boxes whose content is dynamically defined, the options
I have the PHP code below. It is supposed to select up to ten
I have a select defined in mapper.xml file: <mapper namespace=foo> <select id=selectWithRoles parameterType=String resultMap=personWithRoles>
I want to select all elements that have an accesskey defined on them. I
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I have defined a table type PL/SQL variable and added some data there. create
At point (3) in my code I have defined a query called query1 in
I have two tables as defined below: EMAILS ID SUBJECT BODY 1 Test1 blah

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.