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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:26:58+00:00 2026-06-09T18:26:58+00:00

I am using knockout to build a user interface for the following situation: –

  • 0

I am using knockout to build a user interface for the following situation:
– I have an array of items. Each item has an array of item details.
– An item detail can be of one of two types: ‘Type A’ or ‘Type B’.
– If an item detail is of type of A, it can have one of two subtypes: ‘Subtype A-1’ and ‘Subtype A-2’.
– If an item detail is of type of B, it does not have a subtype.

My fiddle

I have the two questions/problems:

  1. I’d like to add/remove the ‘Detail Subtype’ dropdown based on the value of the ‘Detail Type’ dropdown. For example, if the user selects ‘Type B’, I’d like to remove the ‘Detail Subtype’ dropdown. I also would like to set value of the underlying ‘subtype’ property to null. I played with the if binding but to no avail
  2. In the addItemDetail method of the view model, how can I add a new item detail?
  • 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-09T18:27:00+00:00Added an answer on June 9, 2026 at 6:27 pm

    The item details are an observable array containing regular objects that contain regular properties, not observables. You’ve already created a “pm.itemDetail” constructor function, so why don’t you use that?

    pm.Item = function(name, itemDetails) {
        // ...    
        var details = [];
        for (var i = 0; i < itemDetails.length; i++) {
            details.push( new pm.ItemDetail(itemDetails[i]) );
        }
        self.itemDetails = ko.observableArray(details);
    };
    

    I’ve updated the pm.ItemDetail function a bit:

    pm.ItemDetail = function(data) {
        var self = this;
        self.name = ko.observable(data.name);
        self.type = ko.observable(data.type);
        self.subtype = ko.observable(data.subtype);
    };
    

    Now you’re able to use the “visible” binding (the “if” binding hides the content of a DOM node, not the node itself):

    data-bind="visible: type() == 1, ..."
    

    To add a new item detail, just create an instance of “pm.ItemDetail” and push it to the itemDetails array of the currently selected item:

    addItemDetail = function(item) {
        selectedItem().itemDetails.push(new pm.ItemDetail({
            name: "Please enter a name",
            type: 1,
            subtype: 1
        }));
    };
    

    http://jsfiddle.net/XscRT/6/

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

Sidebar

Related Questions

I am using knockout and have an array Properties and each Property can have
I want to build a client for my REST-Service using Knockout.js. I have a
I just started using knockout.js and it works great with normal bidings. I have
A bit of a mystery has cropped up using knockout (2.1.0) and knockout mapping
Using android 2.3.3, I have a background Service which has a socket connection. There's
I am using Knockout Js for my view page. I have a requirement where
I am using knockout.js and upshot.js to get a list of items from API
I am using knockout.js to display a list of employees. I have a single
I'm using Knockout with jQuery and jQuery templates. Assume that I have a template
I'm using Knockout in UI for my website, i have a problem with input

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.