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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:40:34+00:00 2026-06-01T02:40:34+00:00

If you have several view models on one page, how do you ensure that

  • 0

If you have several view models on one page, how do you ensure that you can keep them synced?
For example, if one item is added or a button clicked on one view model and you want the other view model to be sensitive to that change, can Knockout manage this natively or is it better to use some messaging or pub/sub architecture.

I want to stay away from having to manage observables between models.

  • 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-01T02:40:35+00:00Added an answer on June 1, 2026 at 2:40 am

    Knockout 2.0 does include functionality that lets you do basic pub/sub. Here is a sample where two view models communicate through a mediator.

    var postbox = new ko.subscribable();
    
    var ViewModelOne = function() {
        this.items = ko.observableArray(["one", "two", "three"]);
        this.selectedItem = ko.observable();
        this.selectedItem.subscribe(function(newValue) {
            postbox.notifySubscribers(newValue, "selected");
        });
    };
    
    var ViewModelTwo = function() {
        this.content = ko.observable();
        postbox.subscribe(function(newValue) {
            this.content(newValue + " content");
        }, this, "selected");
    };
    
    ko.applyBindings(new ViewModelOne(), document.getElementById("choices"));
    ko.applyBindings(new ViewModelTwo(), document.getElementById("content"));
    

    The first view model notifies through the postbox on a specific topic and the second view model subscribes to that topic. They have no direct dependency on each other.

    Certainly the postbox would not need to be global and could be passed into the view model constructor functions or just created inside a self-executing function.

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

    Also, the postbox could just be a ko.observable (which includes the ko.subscribable functions).

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

Sidebar

Related Questions

I have a page that contains several forms, by submitting each one of them,
I have a view controller class that has to implement several protocols. Too keep
I have several subviews that are controlled by a navigation controller. One of them
Requirements : I have a table of several thousand questions. Users can view these
I have a form that is generated based on several DataTemplate elements. One of
I have several Rails Active Record Models: ContactEmails, ContactCalls, ContactPostalcards. Each one represent a
I have an application with a view containing several subviews. The subviews did not
Hi I have a view with several User Controls and I pass ViewData to
I currently have a list view which has several rows of data and I
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on

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.