Question

I am trying to figure out the best way/place to parse data that is retrieved by a REST proxy on a ST2 store. I want to be able to control the mapping of the fields in depth. The data contains fields that do not map to any fields in the model and I do not have control over what data is received in the response. I want to selectively map fields that I want while ignoring the others.

Is the best way to do this with a custom proxy? If so, what method would I overwrite to do this?

Was it helpful?

Solution

You can use a combination of mapping and convert on the fields of your model.

Ext.define('Dude', {
    extend: 'Ext.data.Model',
    fields: [
        {
            name: 'name',
            mapping: 'dude.name',
            convert: function(value, record) {
                return value.replace('>', '');
            }
        }
    ]
});

OTHER TIPS

I was able to solve this by setting the mapping property for each field in the model class. If you're using a JSON proxy this is as simply as specifying the JSON path to the object that contains the value.

Ext.define('MyApp.model.Category', {
    extend: 'Ext.data.Model',

    config: {
        idProperty: 'id',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'category_title', type: 'string' },
            { name: 'category_description', type: 'string' },
            { name: 'category_parent', type: 'int', mapping: 'category_parent.id' }
        ]

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top