Search code examples
jsonproxysencha-touch-2storedata-mapping

Custom parsing of fields when loading data into store via proxy in Sencha Touch 2


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?


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('>', '');
                }
            }
        ]
    });