Is it possible to have a statement like:
vm.set("SysInfo.Browser", "Chrome");
Where SysInfo is defined in the Observable object as:
vm.set("SysInfo.Browser", "Chrome");
Where SysInfo is defined in the Observable object as:
vm = kendo.observable({
SysInfo = {
status: "starting",
xhr2: "false",
browser: "",
databases: "",
center: "",
date: "",
zoom: 0
}
5 Answers, 1 is accepted
0

Dr.YSG
Top achievements
Rank 2
answered on 12 Dec 2013, 05:37 PM
The reason I ask is because I have a data-bound template
I tried to change the value of SysInfo data, but it was not updating. I was doing things like
But the values in the bound template were not updating.
This do work if I put everything at the top of the vm (and use
<
div
data-bind
=
"source: SysInfo"
data-template
=
"SysInfoTemplate"
>Remove All DB Data</
div
>
I tried to change the value of SysInfo data, but it was not updating. I was doing things like
var sysInfo = vm.get("SysInfo");
sysInfo.Browser = "Chrome";
vm.set("SysInfo", sysInfo);
But the values in the bound template were not updating.
This do work if I put everything at the top of the vm (and use
data-bind="source: this"
0
Hi Yechezkal,
Yes, you can achieve this by using the set method, however I noticed that the observable is not declared properly. For convenience I prepared this small example - I hope it helps.
Regards,
Alexander Popov
Telerik
Yes, you can achieve this by using the set method, however I noticed that the observable is not declared properly. For convenience I prepared this small example - I hope it helps.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Dr.YSG
Top achievements
Rank 2
answered on 13 Dec 2013, 02:54 PM
I noticed this syntax in your jsbin:
Does that mean that I could also do:
and if one of the items in SysInfo is a ObservableArray (which is MVVM bound to some elements) could I update the entire array at runtime by:
Or will this kill the binding, and what I need to do is first empty the array, and then push each item onto the array (which will cause N change events!).
vm.set("SysInfo.browser", newBrowser);
vm.SysInfo.set("status", "stopping");
vm.SysInfo.set("browser", newBrowser);
vm.SysInfo.set("status", "stopping");
vm.SysInfo.set("DataArray", new kendo.data.ObservableArray(serverReplyJSON));
0
Accepted
Hello again,
Yes, the following notations are interchangeable:
Additionally all arrays within an observable object are instance of kendo.data.ObservableArray, so you could just set the DataArray like so:
You can find a small example that illustrates similar behavior here.
Regards,
Alexander Popov
Telerik
Yes, the following notations are interchangeable:
vm.set(
"SysInfo.browser"
, newBrowser);
vm.SysInfo.set(
"browser"
, newBrowser);
vm.SysInfo.set(
"DataArray"
, serverReplyJSON);
//assuming that serverReplyJSON is a valid JavaScript array
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Dr.YSG
Top achievements
Rank 2
answered on 13 Dec 2013, 04:04 PM
Excellent. maybe this could be added as a note to the documentation for ObservableArray and ObservableObject?