Created
May 21, 2012 16:14
-
-
Save frow/2763080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A reader which is used to read polymorphic associations. | |
* Implementors have to provide a getPolyModel function. | |
*/ | |
Ext.define('Your.PolymorphicReader', { | |
extend : 'Ext.data.reader.Json', | |
extractData : function(root) { | |
var me = this, values = [], records = [], tempModel, i = 0, length = root.length, node, id, record; | |
if(!root.length && Ext.isObject(root)) { | |
root = [root]; | |
length = 1; | |
} | |
for(; i < length; i++) { | |
node = root[i]; | |
tempModel = me.getPolyModel(node); | |
if(tempModel) { | |
me.setModel(tempModel); | |
} else { | |
continue; | |
} | |
values = me.extractValues(node); | |
id = me.getId(node); | |
record = new tempModel(values, id, node); | |
records.push(record); | |
if(me.implicitIncludes) { | |
me.readAssociated(record, node); | |
} | |
} | |
return records; | |
}, | |
root : 'data', | |
totalProperty : 'total', | |
successProperty : 'success' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment