PDA

View Full Version : Error in Proxy - reader has no read method



sarabjeetd
9 May 2012, 11:30 AM
I have a store which works fine upto the point in Server.js where it uses the reader.read() method:
In the Server.js, the response parameter has the right data.
Does anyone know what is wrong with the reader config that it has no read method?



// code snippet
processResponse: function(success, operation, request, response, callback, scope) {
var me = this,
reader,
result;


if (success === true) {
reader = me.getReader();


// Apply defaults to incoming data only for read operations.
// For create and update, there will already be a client-side record
// to match with which will contain any defaulted in values.
reader.applyDefaults = operation.action === 'read';


result = reader.read(me.extractResponseData(response));


Here is the store code:


Ext.define('M1', {
extend: 'Ext.data.Model',
fields: ['path', 'metrics']
});
var model1 = Ext.create('M1');

var store1 = Ext.create('Ext.data.Store', {
model: model1,
id: 'chartStoreId' + Math.floor(Math.random()*100000),
idIndex: 0,
autoLoad: false,
autoDestroy : false,
buffered: true,
proxy: {
type: 'jsonp',
url: "some url",
reader: {
type: 'json',
root: 'records'
}
}
});


var callback = function(records, operation, success, config) {
console.log("store callback called");
};
store1.addListener('load', callback,this,{});

store1.load();

sarabjeetd
9 May 2012, 12:29 PM
It fails in Reader.js indicating the model has no prototype member and therefore has no fields property.
Reader.js


if (me.model && me.model.prototype.fields) {
me.buildExtractors();
}

vietits
9 May 2012, 4:38 PM
You should use model class not model instance for store.


Ext.define('M1', {
extend: 'Ext.data.Model',
fields: ['path', 'metrics']
});
// var model1 = Ext.create('M1');


var store1 = Ext.create('Ext.data.Store', {
// model: model1,
model: 'M1',
id: 'chartStoreId' + Math.floor(Math.random()*100000),
idIndex: 0,
autoLoad: false,
autoDestroy : false,
buffered: true,
proxy: {
type: 'jsonp',
url: "some url",
reader: {
type: 'json',
root: 'records'
}
}
});