How to carry the data from one viewModel to another ViewModel Knockout JS

前端 未结 2 1635
感动是毒
感动是毒 2020-12-21 21:14

I am using the Knockout js in my single page Application,I need to carry the value of one viewmodel data to another viewModel data,So i can reduce my duplication creating sa

2条回答
  •  执念已碎
    2020-12-21 21:59

    You could try to gather ur instanced view models in an object, then run applybindings on this object. You would have to rescope the stuff u already have binded. But with this you should be able to cross reference between the models by accessing for instance vm.EmployeeViewModel.SomeFunction()

    var vm = {};
    vm.EmployeeViewModel = new EmployeeViewModel();
    vm.DepartmentViewModel = new DepartmentViewModel();
    ko.applyBindings(vm);
    

提交回复
热议问题