Click here to Skip to main content
15,790,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a site that gets company related data back from the Data Base. E.g.Finance, IT and so forth.

there were separate tables for each department. I then realized that the tables have the same data fields so I created one table to hold all the data and within this table I created a pageIdentifier field which I use to identify what page I’m on and data relating to that page.

The code had different View Models for each page.(had an ITViewModel , FinanceViewModel) I then created a pageIdentifier variable in each View Model which I send back to the stored proc so I know what data I want returned. E.g.
self.pageIdentifier = ko.observable("IT"); //this will load the IT data I have in the DB

I had duplicate View Models with duplicate code. I now created just one View Model to get rid of the duplicate code. So I just have a masterViewModel(where I load the other view models in) and my genericDataViewModel.

Does anyone know how to pass a string value from one view Model to another view Model? I want to pass a string from my MasterViewModel to my genericViewModel.

hope this makes sense.

What I have tried:

I tried creating variables in my MasterView Model:
in this example I tried to create a IT string to pass to my genericView model.

self.navigateToGenericData = function () {
     self.identifierString = "IT";
     $('#content').load("App/GenericData/Browse.html", function () {
         ko.applyBindings(self.genericDataViewModel, $('#content')[0]);

     $('#content').show({ effect: "drop", direction: "up" });

My genericViewModel
function GenericDataViewModel() {
    var self = this;

    self.identifier = ko.observable("IT");
    self.classification = ko.observable();
    self.location = ko.observable();
    self.documentStatus = ko.observable();

in place of self.identifier = ko.observable("IT") i want to get the value from my MasterView model.

I tried doing something like self.identifier = $parent.IdentifierString, but not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900