PDA

View Full Version : Error: reader.read is not a function



titombo
15 Sep 2011, 4:11 AM
Hi everybody,

I would like to know what to do in the situation where I have the model:



//MODEL
Ext.define('StockAddressGrid.model.StockAddress',
{
extend: 'Ext.data.Model'
, fields: ['Id', 'AddressName', 'Description', 'AddressType', 'IsActive']
, proxy: {
type: 'ajax' ,
api: {
read: '/StockAddress/StockAddress/StockAddressList'
, extraParams: { total: 50000}
, reader:
{
type: 'json'
, root: 'StockAddresses'
, successProperty: 'success'
, totalProperty: 'total'
}
,
simpleSortMode: true
}
});


The store:



//STORE
/// <reference path="ext-4.0/ext-all.js" />
Ext.define(
'ReceiveInventoryPart.store.ReceiveInventoryParts'
,{
extend: 'Ext.data.Store'
, model: 'StockAddressGrid.model.StockAddress'
, proxy:
{
type: 'ajax'
,api:
{
read: '/StockAddress/StockAddress/ActiveStockAddressList'
},
extraParams:
{
total: 50000
}
, reader:
{
type: 'json'
, root: 'ReceiveInventoryParts'
, successProperty: 'success'
, totalProperty: 'total'
}
, simpleSortMode: true
}
, autoLoad: true
, pageSize: 200
, remoteSort: true
, remoteFilter: true
, buffered: true
, sorters: ['AddressName']
});




and the application:




/// <reference path="ext-4.0/ext-all.js" />
Ext.Loader.setConfig({ enabled: true });

Ext.application(
{
name: 'ReceiveInventoryPart',
appFolder: '../../Ext.js/app',
models: ['StockAddress'],
stores: ['ReceiveInventoryParts'],
launch: function ()
{
var receiveInventoryPartStore = this.getReceiveInventoryPartsStore();

Ext.create('Ext.form.ComboBox',
{
id: 'cmbStockAddrress',
name: 'cmbStockAddrress',
store: receiveInventoryPartStore,
queryMode: 'remote',
renderTo: 'stockAddressExt',
valueField: 'AddressName'
});
}
});



The data that is coming from the server has the JSON format:

{"ReceiveInventoryParts":[{"Id":1,"AddressName":"aadd"},{"Id":2,"AddressName":"casas"},{"Id":3,"AddressName":"ccc"}]}

The combobox is rendered, but I can't get the items, so I get the exception:

reader.read is not a function
result = reader.read(me.extractResponseData(response));


Please, I would like to know what I am doing wrong?
And can I use this structure, without Controller and using a Model for different Stores?

Thanks,
Tito

mberrie
15 Sep 2011, 4:26 AM
Well, I recommend to format your code with proper line intends. Hint: that might also point you to a problem in your model's proxy config.

titombo
15 Sep 2011, 5:23 AM
Well, I recommend to format your code with proper line intends. Hint: that might also point you to a problem in your model's proxy config.

I am overriding it's behavior defining the proxy on the store.
Because this model is used by another stores.

mberrie
15 Sep 2011, 6:13 AM
I can see that you override the proxy on your store.

The error 'reader.read is not a function' tells me that something is wrong with your reader config. Clearly the 'reader' object is there, but doesn't have a 'read' method. So something is wrong here.

I can see 2 problems:

The proxy config in 'StockAddressGrid.model.StockAddress' is invalid. If you format the code properly you should be able to spot it - not sure if you have problems with the forum software or this is how you format your code.
In 'StockAddressGrid.model.StockAddress' you define the API and its read method. Maybe this causes some havoc. You could just use the url property and see if this changes anything.
If you use 4.0.2a I've read that there are some issues with proxies. E.g. see here (http://www.sencha.com/forum/showthread.php?144963-quot-You-are-using-a-ServerProxy-but-have-not-supplied-it-with-a-url-quot-but-I-have).

nitsko
15 Sep 2011, 6:14 AM
I have been struggling with the same problem since yesterday. Looks lke Ext doesn't recognize the model.

mberrie
15 Sep 2011, 6:18 AM
It might actually be a combination of (1) and (3). (3) might cause the proxy from the Model to kick in (due to a bug in 4.0.2a), and that will fail because of (1).