Skip to content

Instantly share code, notes, and snippets.

@flexdevguy
Last active March 9, 2022 17:48
Show Gist options
  • Select an option

  • Save flexdevguy/8e7e8b9c6bdfd7938cddb5c7f39ecc6c to your computer and use it in GitHub Desktop.

Select an option

Save flexdevguy/8e7e8b9c6bdfd7938cddb5c7f39ecc6c to your computer and use it in GitHub Desktop.
Extjs Key value json reader for store
/**
* @class com.flexdevguy.data.reader.KeyValue
* @extends Ext.data.reader.Json
* Key value json reader for store
*/
Ext.define('com.flexdevguy.data.reader.KeyValue', {
extend: 'Ext.data.reader.Json',
alias : 'reader.keyvalue',
getRoot: function(data) {
if (this.rootAccessor) {
data = this.rootAccessor.call(this, data);
}
var values = [],
key;
for (key in data) {
values.push({
key: key,
value: data[key]
});
}
return values;
}
});
var store = Ext.create('Ext.data.Store', {
fields: ['key', 'value'],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'xyz.json',
reader: {
type: 'keyvalue',
rootProperty: 'jsonroot'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment