How do you map remote JSON to the model?

7 posts, 1 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 07 May 2012 Link to this post

    I see this example but that's binding the data into a dropdownlist...I want me JSON from the server to BE the model Like this

    Is it not doable, or am I missing something?
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 May 2012 Link to this post

    Hello,

     The Kendo DataSource is meant to work with a set of data and not a single model. Perhaps you can use the good old $.ajax to retrieve your model. Something like this: http://jsfiddle.net/korchev/hDfDc/2/ 


    Regards,

    Atanas Korchev
    the Telerik team
    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
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 08 May 2012 Link to this post

    OHHHHH Ok!  I think I see...so can you point me at the kendo documentation for this line?

    // extend the viewModel with the response from the server
    $.extend(viewModel, model);

    I assume this then puts all the data coming back onto the root viewModel object right...

    I guess the difference between Knockout and Kendo MVVM is knockout needs converting to .observable() where kendo you just need to give it the raw json and everything is automatically observable?

  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 May 2012 Link to this post

    Hi,

     Here is the documentation for $.extend - it is part of jQuery actually. If you have nested objects in your model you need to change that line to:

    $.extend(viewModel, kendo.observable(model)); 

    Regards,

    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 08 May 2012 Link to this post

    Ok yeah thanks, I figured it was good'ol jquery, but I was wondering if you had any kendo docs that explains what's going on and demos this?...perhaps a demo for the Q2 enhanced help\docs\demos page?

    Also can you comment on the other question?  Kendo MVVM doesn't need to explicitly set observable, everything is always by default observable?
  7. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 May 2012 Link to this post

    Hello,

     kendo.observable() makes everything observable by default. Of course $.extend does not know neither of Kendo nor of observable objects so you have to do this if you want to convert the model to observable before merging it with the root view model:

    $.extend(viewModel, kendo.observable(model));  

    As for documentation - we don't have any documentation yet which shows how to use $.extend with an observable object. I guess the only gotcha is to use kendo.observable() for the second argument.

    Regards,
    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 08 May 2012 Link to this post

    Thank you sir :)

    You should throw this in the new docs...I think (for me anyway) big selling feature over knockout to not have to make everything observable.
Back to Top
Kendo UI is VS 2017 Ready