is is possible to get the binded ViewModel JavaScript object from a given DOM element?
ko.applyBindings( gLoginViewModel, document.getElementById("login-form") );
ko.applyBindings( gLoginViewModel, document.getElementById("register-form") );
and somewhere else - in rather unrelated code - something like this:
var viewModel = ko.getViewModel( formElement );
viewModel.someObservable( someData ); // observable available in all ViewModels
it would even be better if I could do something like:
var viewModel = ko.getViewModel( someChildElement );
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…