View Full Version : Add a variable in "Ext.data.Model.load"...

31 Jul 2012, 12:32 AM

I've developped a JSON RPC proxy implementation for Ext 4.1.1.
The problem I'm facing is that the method signatures on the backend are different regarding if we load a single record, or a list of records. As Extjs uses in both cases the read method it would be nice to have a special option parameter to be able to identify if we are loading a single record or a list.

Currently I've overwritten the load method of the Ext.data.Model in order to add a "uniqueRecordLoading" parameter. The resulting method looks like this :

Ext.data.Model.load = function(id, config) {
config = Ext.apply({}, config);
config = Ext.applyIf(config, {
action: 'read',
id : id,
uniqueRecordLoading : true // This parameter is needed by the service proxy !

var operation = new Ext.data.Operation(config),
scope = config.scope || this,
record = null,

callback = function(operation) {
if (operation.wasSuccessful()) {
record = operation.getRecords()[0];
Ext.callback(config.success, scope, [record, operation]);
} else {
Ext.callback(config.failure, scope, [record, operation]);
Ext.callback(config.callback, scope, [record, operation]);

this.proxy.read(operation, callback, this);

Best regards