2015-08-31 76 views
1

我有一個視圖模型文件,在執行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?幫助讚賞!

+0

嘗試以確保我明白這一點,但你的看法有JavaScript的呢? –

回答

0

您可以嘗試設計自己的視圖模型是這樣

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 
相關問題