0

I have a Kendo Observable object which contains SharePoint site and folder metadata. I tried adding site objects by using dot notation and the provided Observable.set() method.

They get added to the object, when I check the object, the new site object really gets added to the Observable. But when I call toJSON I only get the initial Observable that was created on page load.

var folder = {
    Id: 0,
    SharePointSite: site,
    RelativeUrl: "",
    IsActive: true
};

configuration.Sites[siteIndex] = site;
configuration.Folders[folderIndex] = folder; <- plain JS object

configuration.set(`Sites[${siteIndex}]`, site);
configuration.set(`Folders[${folderIndex}]`, folder); <- creates Observable object

loadPartialView($("#sites"), siteOverviewUrl, configuration.toJSON(), siteOverviewLoaded);

I create the folder object myself, the site object is serialized from a form that the user submits. Both get added to the Observable, both are not present after calling configuration.toJSON(). Configuration is my root Observable.

Thank you in advance.

Stephan Bisschop
  • 198
  • 1
  • 12

1 Answers1

0

Kendo Observable continues to update itself, if values are properly modified using set.

However, If JSON conversion is performed, The plain JSON object is returned, which is no more an observable. So, any further changes made to the root observable are not reflected to that JSON object or bindings performed with that JSON.

Hope this code snippet will help and see this demo

var observable = new kendo.data.ObservableObject({ name: "John Doe" });
observable.set("age", "30");
var a = observable.toJSON();

observable.set("height", "6");

console.log("observable", observable); // outputs "Observable"
console.log("json", a); // outputs "JSON"
Muhammad Umar
  • 1,357
  • 13
  • 14
  • I think you misunderstood my question. I'm not adding new objects to the JSON object, I'm only adding new objects to the Observable. When I console.log the Observable, I see the new objects. Whenever I console.log the .toJSON() output, only the initial Observable objects are returned. NOT the newly added objects. – Stephan Bisschop Sep 08 '17 at 13:23
  • Here I have prepared a demo, but its working fine. https://dojo.telerik.com/eFayI/2 – Muhammad Umar Sep 08 '17 at 13:29
  • Thank you, but I know how the Observable works, I've followed the official docs. Configuration is my Observable object and I'm adding new objects like this: configuration.set(`Folders[${folderIndex}]`, new kendo.data.ObservableObject(folder)); AND also tried configuration.set(`Folders[${folderIndex}]`, folder); Where "folder" is just a simple JSON returned from the server. – Stephan Bisschop Sep 08 '17 at 13:36