This is a migrated thread and some comments may be shown as answers.

How do you map remote JSON to the model?

6 Answers 690 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 07 May 2012, 02:45 PM
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?

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 08 May 2012, 08:05 AM
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!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 08 May 2012, 01:53 PM
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?

0
Atanas Korchev
Telerik team
answered on 08 May 2012, 02:14 PM
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!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 08 May 2012, 02:17 PM
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?
0
Accepted
Atanas Korchev
Telerik team
answered on 08 May 2012, 02:34 PM
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!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 08 May 2012, 02:38 PM
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.
Tags
MVVM
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Atanas Korchev
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Share this question
or