Posts

Showing posts from July, 2011

JSON different from Extjs 4 model? code for catching invalid or missing field names

I have a working grid that is recieving data as json, where the json is matching the model. However in the real world, things aren't always this clean and controlled. We may end up with fields missing or entries with the wrong field name, or even extra fields that don't exist in the model. So if we want the process halted if the json does not match the model how can catch it? I extended the Extjs reader class, and then implemented to over-ridden methods from the original class, and sent errors to the console and replaced missing fields with a message. Ext.define('App.Reader', { extend: 'Ext.data.reader.Json', extractData: function(root) { var me = this, values = [], records = [], Model = me.model, i = 0, length = root.length, idProp = me.getIdProperty(), node, id, record; if (!root.length && Ext.isObject(root)) { root =