Click here to Skip to main content
15,885,365 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.

JavaScript
self.navigateToGenericData = function () {
     masterVM.error("");
     masterVM.info("");
     self.identifierString = "IT";
     $('#content').hide();
     ko.cleanNode($("#content")[0]);
     $('#content').load("App/GenericData/Browse.html", function () {
         startProgress();
         $("#progressbar").show();
         ko.applyBindings(self.genericDataViewModel, $('#content')[0]);
         //self.genericDataViewModel.retrieveIdentifier('IT');
         self.genericDataViewModel.retrieveGenericDataList();
         self.genericDataViewModel.retrieveClassification();
         self.genericDataViewModel.retrieveLocationLookup();
         self.genericDataViewModel.retrieveDocumentStatus();
         completeProgress();

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


My genericViewModel
JavaScript
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.
Posted

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