PDA

View Full Version : Reading nested objects values from a form



emilianm
10 Jun 2011, 7:24 AM
Reading nested objects values from a form

At the end of the MVC tutorial (http://docs.sencha.com/ext-js/4-0/#/guide/application_architecture) we are reading all the object values from a form and we are setting this back to our record (that us a user Model object). The corresponding code is the following:




updateUser: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();

record.set(values);
win.close();
this.getUsersStore().sync();
}



It seems that this works very well if the initial object is flat (without other nested objects), like the User object from the example


If, for example, you add an Address nested object as a field to the User object, and if you would like to set back to the object the address.street with the value provided on the form you will discover that the instruction record.set(values); will create a new field called address.street (with the form provided value) instead of modifying the existing street field of the existing address object on our User record.

Do you have any idea on how to resolve this?


Thank you in advance for any hints.

Best regards