I have run into a problem when trying to use several ViewModels referencing the same model.
ViewModels and models are all ObservableObjects.
Please, consider the following simple example:
// observable for model
var model = kendo.observable({ mf: 0 });
// observables for two viewmodels
var vm1 = kendo.observable({ vmFld1: null });
var vm2 = kendo.observable({ vmFld2: null });
// set fields of both viewmodels to the same
// observable model
vm1.set("vmFld1", model);
vm2.set("vmFld2", model);
Both ViewModels bind CHANGE event handlers in ObservableObject.wrap() method.
They are added to the array of CHANGE event handlers of the model and are to be triggered when model field is changed.
E.g. like in the line of code below
// change the value of model field
vm1.set("vmFld1.mf", 1);
These event handlers are invoked in a loop of Observable.trigger() method.
But each event handler modifies the e.field in event argument e.
wrap: function(object, field, parent) {
var that = this;
…
(function(field) {
...
object.bind(CHANGE, function (e) {
e.field = field + "." + e.field;
that.trigger(CHANGE, e);
});
})(field);
...
}
It should work just fine for the case when we have a linear chain of nested ObservableObjects, but in my case it is rather a tree with single ObservableObject root. The second ViewModel gets incorrect "path" to changed field in CHANGE event handler.
In example above the first ViewModel gets "vmFld1.mf" in CHANGE event. Then it modifies the path in its handler and the second ViewModel vm2 gets incorrect path "vmFld2.vmFld1.mf".
As a result, vm2 does not refresh view when View-ViewModel binding is used.
I'm not sure if you already know about this and it might be even already fixed in latest version. But I can look only into available for download open source code which is of 2012.3.1114 version.
I very appreciate if you can resolve this issue. Thank you.