PDA

View Full Version : Field mapping for JS Object



legrego
25 Jun 2012, 4:27 AM
I am trying to instantiate a model using with a JavaScript object stored in a local variable. The 'mapping' property doesn't seem to be working for me. In the example below, "field1" will be correctly populated, but not the other fields. No error is raised, but the mapping seems to be ignored.

I also tried creating a json store (memory proxy, json reader) that used the model, and creating a record for the store instead of populating a model directly, but I got the same result.

The model:


Ext.define('MyApp.model.MyAppModel', {
extend: 'Ext.data.Model',
alias: 'MyAppModel',
fields: [{
name: 'field1'
}, {
name: 'myOtherField',
mapping: 'field2'
}, {
name: 'objectId',
mapping: 'object1.objectId'
}]
});


The data:


var data = {
field1: 'value1',
field2: 'value2',
object1: {
objectId: 5,
objectName: 'My Object'
}
};


Instantiate:


var myRec = Ext.create('MyAppModel', data);

evant
25 Jun 2012, 4:29 AM
Mappings are only applied when they run through the data reader.