I would like to know if it is possible to perform a binding between two objects ( viewmodel
), the first is created as part of the function and the other is created from the Get
, and the property that I would like to synchronize between the two viewModels
is visibleTabs
with ultimoNivel
KnockoutJS.
My current code is as follows:
var vm = function() {
var self = this;
this.visibleTabs = ko.observable(false);
this.select = function(e) {
var idEquipo = treeview().dataItem(e.node).id;
var equipo = Get("equipo/getbyid/" + idEquipo).responseText;
self.equipo(ko.mapping.fromJS(JSON.parse(equipo)));
self.visibleTabs(self.equipo().ultimoNivel());
}
this.visibleTabsChange = ko.computed(function () {
if (self.equipo()) {
self.equipo().ultimoNivel(self.visibleTabs());
}
});}
The solution I found was to change the
computed
KnockouJS function to asubscribe
devisibleTabsChange
, likewise the following lineself.visibleTabs(self.equipo().ultimoNivel());
was also moved to thesubscribe
del propertyequipo
, the code would be as follows: