如何将字符串值从一个js视图模型传递到另一个js视图模型 [英] How do I pass a string value from one js viewmodel to another

查看:79
本文介绍了如何将字符串值从一个js视图模型传递到另一个js视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站可以从数据库中获取公司相关数据。例如,金融,IT等等。



每个部门都有单独的表格。然后我意识到这些表具有相同的数据字段,因此我创建了一个表来保存所有数据,在此表中我创建了一个pageIdentifier字段,用于标识我所在的页面和与该页面相关的数据。 />


代码为每个页面都有不同的View Models。(有一个ITViewModel,FinanceViewModel)然后我在每个View Model中创建了一个pageIdentifier变量,我将其发送回存储的proc我知道我想要返回什么数据。例如,

self.pageIdentifier = ko.observable(IT); //这将加载我在数据库中的IT数据



我有重复的View Models并且代码重复。我现在只创建了一个View Model来摆脱重复的代码。所以我只有一个masterViewModel(我在其中加载其他视图模型)和我的genericDataViewModel。



有谁知道如何将字符串值从一个视图模型传递到另一个视图模型?我想从MasterViewModel传递一个字符串到我的genericViewModel。



希望这是有道理的。



我尝试了什么:



我尝试在我的MasterView模型中创建变量:

在这个例子中我尝试创建一个IT字符串以传递给我的genericView模型。< br $>


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 () {
     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" });
 };





我的genericViewModel



My genericViewModel

function GenericDataViewModel() {
    var self = this;

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





代替self.identifier = ko.observable(IT )我想从我的MasterView模型中获取价值。



我尝试过像self.identifier = $ parent.IdentifierString这样的东西,但没有用。



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.

推荐答案

' #content')。hide();
ko.cleanNode(
('#content').hide(); ko.cleanNode(


#content)[ 0 ]);


' < span class =code-string>#content')。load( App / GenericData / Browse .html function (){
startProgress();
('#content').load("App/GenericData/Browse.html", function () { startProgress();


这篇关于如何将字符串值从一个js视图模型传递到另一个js视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆