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

Error trying to post nested view model

4 Answers 748 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 22 May 2012, 08:23 PM
I am getting the error: Uncaught TypeError: Cannot read property 'field' of undefined 

in the kendo.all.min.js file when trying to post a view model with nested objects. 

I have created a jsfiddle to repro the issue, I don't think I'm describing it very well, so take a look, it is short.

http://jsfiddle.net/bNBUP/ 

Any ideas?
Thanks,
Gary 

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 24 May 2012, 11:25 AM
Hi,

 This is caused by the fact that the toJSON method is not recursive right now. We decided to implement this for the next internal build.

 As a workaround you could call toJSON of the nested objects: http://jsfiddle.net/bNBUP/1/ 

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
Gary
Top achievements
Rank 1
answered on 24 May 2012, 03:09 PM
Thanks for the reply and explanation.  I ended up falling back to JSON.stringify (which is completely fine in my opinion - no need for you to reinvent the wheel) since in my real world case the objects were nested several objects deep.

Gary
0
Kevin
Top achievements
Rank 2
answered on 02 Jun 2012, 01:01 PM
Was this addressed or where can I find an internal build? I couldn't seem to find it for the Kendo UI builds in my subscription. I see where I can download Telerik ASP.NET Ajax internal builds as well as others...

The following was what I ended up implementing to get around the current issue. I do not know what type of model I will be submitting as it is generic and a pass through for any type:
var tempData = viewModel.toJSON();
$.each(tempData, function (i, v) {
     if (v && typeof (v) == "object") {
          tempData[i] = tempData[i].toJSON();
     }
});
return tempData;

This only goes down one level. A recursive function would need to be used to traverse further. Do you know when it is planned to make toJSON() a recursive call?


0
Atanas Korchev
Telerik team
answered on 04 Jun 2012, 06:49 AM
Hi Kevin,

 You could download the latest internal build from the corresponding page on kendoui.com (you have to be logged in): http://www.kendoui.com/account/your-products/product-versions/single-download.aspx?pmvid=2784&pid=949 

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!
Tags
MVVM
Asked by
Gary
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gary
Top achievements
Rank 1
Kevin
Top achievements
Rank 2
Share this question
or