【问题标题】:How to access a variable defined in view-model from view file如何从视图文件访问视图模型中定义的变量
【发布时间】:2015-08-31 17:50:24
【问题描述】:

我有一个视图模型文件,在执行 loadCustomer 函数时,我将变量设置为 true。

 loadCustomer: function () {
     CustomerViewModel.set("CustomerDetails",CustomerViewModel.CustomerDataSource._data[0]);
     var initialCustomerLoad = true;
 },

如何从我的视图文件中访问 initialCustomerLoad?我希望能够检查 initialCustomerLoad 是否为假然后做一些事情......

if (initialPatientDataLoad != true) {
    // my business logic will be going here.              
}      

我该怎么做?如何从我的视图文件中访问 initialPatientDataLoad?感谢您的帮助!

【问题讨论】:

  • 试图确保我理解这一点,但您的视图中有 javascript 吗?

标签: javascript jquery mvvm kendo-ui


【解决方案1】:

您可以尝试将您的视图模型设计成这样

customer.viewmodel.js

var CustomerViewModel = function() {
    // ..some property..
    this.loaded = false;
}

CustomerViewModel.prototype.loadCustomer = function() {
    var self = this;

    //..your operation here
    self.loaded = true;
    return self;
}

用途 customer.view.js

var viewModel = new CustomerViewModel();

viewModel.loadCustomer(data);

if(!viewModel.loaded) {
   //..your code here
}
// futher implementation

【讨论】:

    猜你喜欢
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 2016-06-25
    相关资源
    最近更新 更多