是否可以随时在页面上的任何脚本中访问viewModel属性?在下面的模型中,我想使用currModel作为存储某个标志的地方,我可以不将它绑定到DOM中的某些内容吗?感谢任何帮助。
function viewModel(result,currentTheme) {
var self = this;
self.isBlankForm = !(result.payload.isBlankForm);
self.snapEdit = result.payload.emailText;
self.snapEditSuccess = result.payload.successBody;
self.isMeNotified = result.payload.isMeNotified;
self.isEmailSentToUser = result.payload.isEmailSentToUser;
self.fromEmailBox = result.payload.fromUserEmail;
self.subjectEmailBox = result.payload.emailSubject;
self.themeNames = ko.observableArray(result.payload.themeList);
self.themeChoice = ko.observable(self.themeNames.find("id", currentTheme));
self.bgColor = result.payload.bgColor;
self.frmColor = result.payload.frmColor;
self.txtColor = result.payload.txtColor;
self.btnColor = result.payload.btnColor;
self.btnTxtColor = result.payload.btnTxtColor;
self.currModel = ko.observable();
}
答案 0 :(得分:0)
当然,只需将您的VM存储在变量中即可。
例如:
var myVM = new viewModel();
ko.applyBindings(myVM);
现在,您可以随时访问myVM.currModel()
。