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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:25:25+00:00 2026-06-09T03:25:25+00:00

Let’s say I have three objects like this: var registryEpisode = function() { var

  • 0

Let’s say I have three objects like this:

var registryEpisode = function() {
        var self = this;

        self.registry = ko.observable(new registry());
        self.episodeType = ko.observable(new episodeType());
    };

    var episodeType = function() {
        var self = this;
        self.id = ko.observable(""),
        self.name = ko.observable("");
    };
var registry = function() {
    var self = this;

    self.id = ko.observable(""),
    self.name = ko.observable("");
};

Then I have a view model like this:

    var vm = function() {
    var self = this;
    self.registryEpisodeTypes = ko.observableArray([new registryEpisode()]);

    self.addRegistryEpisodeType = function (episodeType, registry) {
    var regEpisode = new registryEpisode();
    regEpisode.registry = registry;
    regEpisode.episodeType = episodeType;
            self.registryEpisodeTypes.push(regEpisode);

        } .bind(this);
    }

I’m trying to bind the view model to a table of dropdown lists and have the view model updated each time a registry and episode type is selected, but I need to maintain the relationship between episodesTypes and registries. Thoughts?

  • 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-09T03:25:27+00:00Added an answer on June 9, 2026 at 3:25 am

    Here is a simple implemantion of a chain dropDownLists: jsFiddle

    var registryEpisode = function() {
        var self = this;
    
        self.registry = ko.observable(new registry());
        self.episodeType = ko.observable(new episodeType());
    };
    
    var episodeType = function(id, name) {
        var self = this;
        self.id = ko.observable(id), self.name = ko.observable(name);
    };
    
    var registry = function() {
        var self = this;
    
        self.id = ko.observable(""), self.name = ko.observable("");
    };
    
    var vm = function() {
    
        var self = this;
        self.selectedRegistry = ko.observable("");
        self.registryEpisodeTypes = ko.observableArray([]);
    
        self.addRegistryEpisodeType = function(episodeType, registry) {
            var regEpisode = new registryEpisode();
            regEpisode.registry = registry;
            regEpisode.episodeType = episodeType;
                self.registryEpisodeTypes.push(regEpisode);
    
        }.bind(this);
    
        self.getRegistries = function() {
    
            var hashCheck = {};
            var result = ko.observableArray([]);
            ko.utils.arrayMap(self.registryEpisodeTypes(), function(item) {
                    if (hashCheck["" + item.registry.id()] === null || hashCheck["" + item.registry.id()] === undefined) {
                    hashCheck["" + item.registry.id()] = item.registry.name();
                    result.push({
                        "name": item.registry.name(),
                        "value": item.registry.id()
                    });
                }
            });
            return result;
        }
    
        self.getEpisodes = ko.dependentObservable(function() {
            var ret = self.registryEpisodeTypes();
            var selectedRegistryItem = self.selectedRegistry();
            if (selectedRegistryItem === null || selectedRegistryItem === undefined || selectedRegistryItem === "")
                return ;
            var result = ko.observableArray([]);
            ko.utils.arrayMap(ret, function(item) {
                if (item.registry.id() == selectedRegistryItem) result.push({
                    "name": item.episodeType.name(),
                    "value": item.episodeType.id()
                });
            });
            console.log(ko.toJSON(result));
                return result;
    
        });
    }
    
    var viewModel = new vm();
    
    var breakingBad = new registry();
    breakingBad.id("1000");
    breakingBad.name("Breaking Bad");
    viewModel.addRegistryEpisodeType(new episodeType("1", "E1-breakingBad"), breakingBad);
    viewModel.addRegistryEpisodeType(new episodeType("2", "E2-breakingBad"), breakingBad);
    viewModel.addRegistryEpisodeType(new episodeType("3", "E3-breakingBad"), breakingBad);
    
    var trueBlood = new registry();
    trueBlood.id("1001");
    trueBlood.name("True Blood");
    viewModel.addRegistryEpisodeType(new episodeType("1", "E1-trueBlood"), trueBlood);
    viewModel.addRegistryEpisodeType(new episodeType("2", "E2-trueBlood"), trueBlood);
    viewModel.addRegistryEpisodeType(new episodeType("3", "E3-trueBlood"), trueBlood);
    
    ko.applyBindings(viewModel);
    
    <div>   
        <span data-bind="text:selectedRegistry"></span>
    </div>
    <div>
        <select data-bind="options:getRegistries(),optionsText:'name',optionsValue:'value',value:selectedRegistry"></select>   
    </div> 
    <div>
        <select data-bind="options:getEpisodes(),optionsText:'name',optionsValue:'value'"></select>
    </div>
    

    I create a dependentObservable called getEpisodes. Whenever selectedRegistry changes this episodeList calculated again.

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

Sidebar

Related Questions

Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say I have some json like this in mongo: {n:5} and a java
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:

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.