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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:33:25+00:00 2026-05-26T11:33:25+00:00

I’m trying to understand how the variables are observed and mapped. The jsfiddle is

  • 0

I’m trying to understand how the variables are observed and mapped. The jsfiddle is here http://jsfiddle.net/rniemeyer/adNuR/. The following 2 lines of javascripts seem to set up the variables for observation:

this.category = ko.observable();
this.product = ko.observable();

So how do the above 2 lines do the tricks? How does it know how to map the category and product into the sampleProductCategories[] array?

Thanks for the help.

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

    The fiddle loads a resource that contains all of the choices that live in the sampleProductCategories array: http://knockoutjs.com/examples/resources/sampleProductCategories.js

    Each cartLine object has category and product observables to hold the current choice.

    For example, here is one of the bindings for the individual cartLine:

    <select data-bind='options: sampleProductCategories, optionsText: "name", optionsCaption: "Select...", value: category' />
    

    This says that the options in the dropdown should come from sampleProductCategories. The value in the box should be the name property and when a selection is made, it should be put into the category of the cartLine.

    So, when a selection is made, category now equals the appropriate object from the sampleProductCategories array. Something like:

    {
        "products": [{
            "name": "1950's Chicago Surface Lines Streetcar",
            "price": 26.72
        }, {
            "name": "1962 City of Detroit Streetcar",
            "price": 37.49
        }, {
            "name": "Collectable Wooden Train",
            "price": 67.56
        }],
        "name": "Trains"
    }
    

    Now, the second dropdown binding looks like:

    <select data-bind='visible: category, options: category() ? category().products : null, optionsText: "name", optionsCaption: "Select...", value: product' />
    

    This binding shows up if a category has been selected. The options come from the products array of the selected category. When a value is selected, then the product observable will be populated with the appropriate object from the array. Like:

    {
         "name": "Collectable Wooden Train",
         "price": 67.56
    }
    

    So, the dropdowns work together to provide nested options.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.