PDA

View Full Version : MapReader



Axel
29 Nov 2007, 9:23 AM
Hello all,

In case anyone is interested, here is a MapReader:



Ext.data.MapReader = function(){
Ext.data.MapReader.superclass.constructor.call(this, null, [
{name: 'key', mapping: 'key'},
{name: 'value', mapping: 'value'}
]);
};
Ext.extend(Ext.data.MapReader, Ext.data.DataReader, {
read : function(response) {
var records = [];
for (var dataItem in response) {
var record = new this.recordType({ key: dataItem, value: response[dataItem] }, null);
records[records.length] = record;
}
return {
records : records,
totalRecords : records.length
};
}
});


I use it together with Dwr & the ComboBox component.

It expects data in this format:

{myKey:"myValue",myKey2:"myValue2",myKeyN:"myValueN"}

Cheers,
Axel

totodo
6 Dec 2007, 4:38 AM
good job!! ,it's very useful..