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

  • Home
  • SEARCH
  • 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 9244131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:57:17+00:00 2026-06-18T08:57:17+00:00

I am trying to create and initialize some sort of master view model that

  • 0

I am trying to create and initialize some sort of master view model that contains common view models that might be run on every page and page specific models that are appended on page load.

var MasterViewModel = {
   commonViewModel1 : CommonViewModel1(),
   commonViewModel2 : CommonViewModel1()
};

var commonInit = function() {
  // Populate View Model Data
  MasterViewModel.commonViewModel1 = initCommonViewModel1();
  MasterViewModel.commonViewModel2 = initCommonViewModel2();

  // Apply common view model bindings
  ko.applyBindings(MasterViewModel);
};

var pageSpecificInit = function() {
  // Populate Specific View Model Data
  MasterViewModel.pageViewModel1 = initPageViewModel1();
  MasterViewModel.pageViewModel2 = initPageViewModel2();

 // Apply Page Specific Bindings
 ko.applyBindings(MasterViewModel);
};

$(function() {
  commonInit();
  pageSpecificInit();
});

this is a crude example of what I am trying to do in the real application this is all namespaced and in separate files so that only page specific code is run. What is the best practice for doing this I somewhat based the above on http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html but when I do it in the application I get something like “cannot bind to pageViewModel1 undefined” should I setup my MasterViewModel differently to be more like

var MasterViewModel = {
   commonViewModel1 : CommonViewModel1(),
   commonViewModel2 : CommonViewModel1(),
   pageViewModels : {}
};

    var commonInit = function() {
  // Populate View Model Data
  MasterViewModel.commonViewModel1 = initCommonViewModel1();
  MasterViewModel.commonViewModel2 = initCommonViewModel2();

  // Apply common view model bindings
  ko.applyBindings(MasterViewModel);
};

var pageSpecificInit = function() {
  // Populate Specific View Model Data
  MasterViewModel.pageViewModels.pageViewModel1 = initPageViewModel1();
  MasterViewModel.pageViewModels.pageViewModel2 = initPageViewModel2();

 // Apply Page Specific Bindings
 ko.applyBindings(MasterViewModel.pageViewModels);
};

$(function() {
  commonInit();
  pageSpecificInit();
});
  • 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-18T08:57:19+00:00Added an answer on June 18, 2026 at 8:57 am

    Your second example is more correct, but shouldn’t you be binding the page-specific view models to a specific html element that you’ve surrounded with the stop binding comment?

    ko.applyBindings(MasterViewModel.pageViewModels, $('#pageElement')[0]);
    

    However, if you want to have nicely decoupled objects that can talk to each other, then you might want to look at Knockout Postbox

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

Sidebar

Related Questions

I am trying to initialize directX, but for some reason it can't create d3d
I am trying to create a function that generates an rectangle with some text
Am trying to write some tests that create/remove/change users using a CustomMembershipProvider. The CustomMembershipProvider
I'm trying to create a service bean that when referenced will be initialized with
Trying to create a black line in my view to separate text blocks but
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I am trying to create a separate model class for image uploading, which was
What I'm trying to do is create a class that I can quickly attach
I am trying to create a SIMPLE plugin, no interface is necessary, that will
I am trying to create a custom UIView that is stored in a nib

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.