[英]How to update view model data from another view model in Knockout
I am using Knock out to bind different sections in a page. 我正在使用敲除绑定页面中的不同部分。 I have two view model data for each section.
每个部分都有两个视图模型数据。 While changing a element in one view model based on that want to change another element in another view Model.Each view model data have ID field to identify each data.
在一个视图模型中基于要更改另一个视图模型中的另一个元素的元素时,每个视图模型数据都有ID字段以标识每个数据。
You can just pass one of the view model in to the other view model: 您可以将其中一个视图模型传递给另一个视图模型:
var ViewModel1 = function() {
var self = this;
self.selectedItem = ko.observable();
};
var ViewModel2 = function(viewModel) {
self = this;
self.content = ko.observable();
viewModel.selectedItem.subscribe(function(){
self.content('value changed')
});
};
var viewModel1 = new ViewModel1();
var viewModel2 = new ViewModel2(viewModel1);
ko.applyBindings(viewModel1, document.getElementById("part1"));
ko.applyBindings(viewModel2, document.getElementById("part2"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.