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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:16:31+00:00 2026-05-27T10:16:31+00:00

Am I able to bind the optionsValue of a select list to the index

  • 0

Am I able to bind the optionsValue of a select list to the index of
the particular item in the option array?

<select data-bind="options: options,  optionsText: 'text', 
optionsValue: ko.utils.arrayIndexOf(**somevalue**)" /> 

Or am I stuck with having to transform my options object from

{ 
    text: 'asdasd' 
} 

to

{ 
   text: 'asdasd', 
   id: 0 
} 

and doing

<select data-bind="options: options,  optionsText: 'text', 
optionsValue: 'id' /> 

Thanks

  • 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-05-27T10:16:31+00:00Added an answer on May 27, 2026 at 10:16 am

    If you are communicating via JSON rather than submitting a form, then you can have the selected value be your object and create a dependentObservable to represent the index of it like:

    function ViewModel() {
        this.choices = ko.observableArray([
            { text: "index zero" },
            { text: "index one" },
            { text: "index two" }
        ]);
        this.selectedChoice = ko.observable();
        this.selectedChoiceIndex = ko.dependentObservable(function() {
            return this.choices.indexOf(this.selectedChoice());
        }, this);
    };
    

    Sample: http://jsfiddle.net/rniemeyer/hevTF/

    If you are submitting a form and are relying on the value attribute of the selected option element, then you would want to add the index to your object (as you had suggested). The other option is to emit the option elements in a jQuery template using {{each(item, index)}} like: http://jsfiddle.net/rniemeyer/h6wLr/

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

Sidebar

Related Questions

I'm able to bind the optionsText but not the optionsValue. Should both functions be
I'm not able to bind events to a list that is generated by jQuery.
I am able to bind my datasource to the textblock for the display text.
I have created a kendo.data.dataSource with success, and I am able to bind it
I want to be able to bind a single and double click event to
In WPF and SubSonic 2 using Active Record, I was able to bind to
Not able to store all binary data values into sqlite3 table using QT. For
Im able to populate my formset with the elements of an array which is
not able to get this, can someone help for this LINQ query? select col1,
I need to be able to access a list throughout my Rails project. 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.