PDA

View Full Version : Model not firing field mapping to transform data



Jangla
25 Feb 2013, 6:13 AM
I'm probably completely wrong here but it would seem from the docs that loadRecord only requires that you pass it a model.

So I'm trying this code out:



record = {
classRef: {
id : 'my.class.ref',
name : 'myClassRef'
},
id: 10
name: 'My Name'
}


Ext.define('Ext.myApp.model.myModel', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name : 'id', type : 'int'},
{name : 'name', type : 'string'},
{name : 'classRef', type : 'string', mapping : 'classRef.id'}
]
});




myWin.down( 'form' ).getForm().loadRecord( Ext.create('Ext.myApp.model.myModel', record ))



As I understand it, this should result in data that resembles this:



json = {
classRef: 'my.class.ref',
id: 20
name: 'My Name'
}





However, what we end up getting in the classRef form field is this:




<input id="hiddenfield-1031-inputEl" type="hidden" name="classRef" value="[object Object]" style="width:100%;" class="x-form-field x-form-hidden " autocomplete="off" aria-invalid="false" data-errorqtip="">



So it's pretty clear here that the classRef mapping in the model isn't being applied.

What am I missing?

mitchellsimoens
27 Feb 2013, 8:07 AM
I believe the mapping has to be run through the reader to work.

Jangla
27 Feb 2013, 8:09 AM
I believe the mapping has to be run through the reader to work.

How do I do that within the context of the example I posted?