I am using DOJO 1.8 iand spring mvc. I want to convert my form fields to JSON objects and pass it to the controller. Using DOJO dom-form.toObject(“myForm1”) i am able to pass the Json to the controller if it is a simple object.
If my model object is having inner objects then the .toObject() is not able to convert that into nested JSON objects.
var formObject1 = domForm.toObject("myForm1");
alert("hi");
require(["dojo/json"], function(JSON){
postData = JSON.stringify(formObject1);
});
dojo.byId("testdiv").innerHTML = postData;
and the Json I am getting is
{“firstName”:”12345″,”middleName”:”Joanna”,”lastName”:”Eliza”,”address.addrLine1″:”add1″,”address.addrLine2″:”add2″,”address.addrLine3″:”add3″,”email”:”12345″}
But I need as below,
{“firstName”:”12345″,”middleName”:”Joanna”,”lastName”:”Eliza”,“address”:{“addrLine1″:”add1″,”addrLine2″:”add2″,”addrLine3″:”add3”},”email”:”12345″}
Does DOJO support this type of JSON conversion?
Dojo has various method for this kind of task. Just look at the documentation and choose a suitable solution.