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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:20:28+00:00 2026-05-24T11:20:28+00:00

Using knockout.js, is it possible to bind to a property of a child object

  • 0

Using knockout.js, is it possible to bind to a property of a child object of a JSON object from the server? Specifically, if I’m given an object from the server that looks like this:

var obj = {
    list: [ { key: "a", value: 1 },
            { key: "b", value: 2 },
            { key: "c", value: 3 }        
        ],
    selected: {
        key: "",
        value: null  
    }
};

I create a viewModel from this javascript object via the “mapping” plugin:

var viewModel = ko.mapping.fromJS(obj);

And I bind list to a <select> tag like so:

<select data-bind="options: list, optionsText: 'key', 
                   optionsValue: 'value', 
                   value: selected">
</select>

I’ve assigned the value to be the selected property of my viewModel. This means, upon selecting an option, I can successfully query viewModel.selected.key() and viewModel.selected.value() in code and get the up-to-date values.

However, I am unable to bind the selected item’s key or value data to be displayed on a span. For instance, this doesn’t display my selected value:

<span data-bind="text: selected.value"></span>

Can I do what I want? Do I need to resort to using a real simple template to establish proper context (ie: selected)?

I have an example of the situation here. I’ve even tried specifically mapping the child selected object to be an observable itself, but with no luck (see commented out mapping call with the additional options).

  • 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-24T11:20:28+00:00Added an answer on May 24, 2026 at 11:20 am

    You were on the right track with the mapping options. You would want selected to be an observable, so your UI updates when you make changes in the dropdown. In your case, it could even be empty.

    One thing to note is that when the mapping plugin deals with an object like:

    selected: { key="", value=null }
    

    It will make key and value observables, but not selected.

    One other issue that you are having is that your first select specifies optionsValue: 'value'. This will cause it to write the value property of your object to selected instead of the object.

    If you want to write the object itself, then you would want to completely remove the optionsValue binding.

    Here is your fiddle with these updates:
    http://jsfiddle.net/rniemeyer/Dubu9/2/

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

Sidebar

Related Questions

I am using Knockout-JS to bind properties in my view to my view model.
I am using Knockout JS library to bind the HTML5 input controls in my
I'm working with a new application at work that we're building out using Knockout.js
I'm using Knockout with jQuery and jQuery templates. Assume that I have a template
I am binding a list of objects to a select using knockout. Object Class
I'm fetching JSON from my ASP .NET website using the following jQuery: $.ajax({ type:
So far in the Knockout.js documentation, they only show using jQuery templates that are
I am trying to populate Select using knockout data-bind option for a list of
I am trying to delete an item from a list. I am using knockout.js
Firefox populates a form with my username/password. This is using knockout.js to bind the

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.