PDA

View Full Version : Store exception



vcheruk
27 May 2013, 4:56 PM
I am new to ExtJS - created a Store and Model as below-- and the error is

Uncaught TypeError: Property 'prgsum' of object [object Window] is not a function

Source Class: http://localhost:8080/?method=prgsum&_dc=1369702453208&page=1&start=0&limit=100&callback=Ext.data.JsonP.callback44 Line 1



Ext.define('MyApp.model.PrgSum', {
extend: 'Ext.data.Model',

idProperty: 'plant',

fields: [
{
name: 'plant'
},
{
name: 'tz'
},
{
name: 'ordcnt'
}
],

proxy: {
type: 'jsonp',
url: 'http://localhost:8080/?method=prgsum',
reader: {
type: 'json',
root: 'data',
successProperty: 'SUCCESS',
totalProperty: 'RESULTS'
}
}
});

// Store

Ext.define('MyApp.store.PrgSumStore', {
extend: 'Ext.data.Store',

requires: [
'MyApp.model.PrgSum'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
model: 'MyApp.model.PrgSum',
storeId: 'idPrgSumStore',
pageSize: 100
}, cfg)]);
}
});

//Data
url: http://localhost:8080/?method=prgsum
prgsum({"data":[ { "plant": "Topeka", "tz": "CST", "ordcnt": "10000" }, { "plant": "Perry", "tz": "EST", "ordcnt": "10000" }, { "plant": "Denver", "tz": "MST", "ordcnt": "10000" }, { "plant": "Rosenberg", "tz": "CST", "ordcnt": "10000" } ],"SUCCESS":true,"RESULTS":4});

evant
27 May 2013, 5:15 PM
Look at the url:



http://localhost:8080/?method=prgsum&_dc=1369702453208&page=1&start=0&limit=100&callback=Ext.data.JsonP.callback44


It's expecting the callback method to be



Ext.data.JsonP.callback44

vcheruk
27 May 2013, 5:19 PM
Is there something I need to include in the Store configuration.

dawesi
27 May 2013, 11:47 PM
when using jsonp

you need to wrap the returned data in a function (in this case Ext.data.JsonP.callback44)

so your data will look like in this case
Ext.data.JsonP.callback44({...})


the mime type of the returned data needs to be text/javascript (not application/json)

so the callback string that is given to the request needs to be used to create the function name that wraps your data coming back from the server. (hint: this is dynamic, so next time it will be callback=Ext.data.jsonP.callback45), so you can't hard code it