How to transform a regular JavaScript object to ObservableObject?

2 posts, 0 answers
  1. fbaptiste
    fbaptiste avatar
    19 posts
    Member since:
    Apr 2007

    Posted 12 Nov 2014 Link to this post

    The kendo documentation specifies two ways to create an observable object: 

    var viewModel1 = new kendo.data.ObservableObject( {
      field1: "value1",
      field2: "value2"
    });
     
    var viewModel2 = kendo.observable( {
      field1: "value1",
      field2: "value2"
    });

    but what should be used when a regular javascript object already exists, and needs to become observable?
    for example, a DTO object that is being returned by a web service or one that is already created as follows:

    var viewModel = {
        name: "John Doe"
    };
  2. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 13 Nov 2014 Link to this post

    Hi Fred,

    Something like this should work - 
    var viewModel = { name: "John Doe" };
     
    viewModel = kendo.observable(viewModel);


    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top