PDA

View Full Version : "Cannot call method 'getProxy' of undefined" when defining a Ext.data.Store



jeanluca
17 Jan 2012, 6:53 AM
Hello

I'm trying to setup a basic application using MVC. The app works fine with models, controllers and views. But when I define a Store I get


Uncaught TypeError: Cannot call method 'getProxy' of undefined

Below is the code of the main applications:


Ext.Loader.setConfig({ enabled: true });

Ext.application({
name: 'Data',
controllers: ['People'],
initialize: function () {
console.log('app initialize');
this.callParent();
},


launch: function() {
console.log('launch') ;
}
}) ; This file is stored in app/

Next, in app/controller I have a file People.js

Ext.define('Data.controller.People', {
extend: 'Ext.app.Controller',
models: ['User'],
stores: ['users'],

init: function() {
},
onLaunch: function() {
}
});
and the model at app/model/User.js

Ext.define('Data.model.User', { extend: 'Ext.data.Model',
alias: 'model.usr',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'}
]
});
});
and finally in app/store/users.js


Ext.create('Ext.data.Store', {
model: 'User',
data: [
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Jamie', lastName: 'Avins' }
]
});
I can see that all files are loaded, so I guess the naming is correct. I also tried to add a proxy to the store


Ext.create('Ext.data.Store', { model: 'User',
data: [
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Jamie', lastName: 'Avins' }
],


proxy: {
type: 'memory',
reader: {
type: 'json',
}
}
});
but then the error I get changes to


Uncaught TypeError: Cannot read property 'prototype' of undefined

Any suggestions ?

Cheers
Luca

mitchellsimoens
17 Jan 2012, 7:07 AM
If you are specifying classes in the stores config of a controller, it expects a class with the name, not just the Ext.create. So you need to use Ext.define to create a new store class like you did for your controller and model.

jeanluca
17 Jan 2012, 7:20 AM
thanks a lot for the quick reply!
I changed my store to


Ext.define('Ext.data.Store', {
model: 'User',
storeId:'users',
data: [
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Jamie', lastName: 'Avins' }
],


proxy: {
type: 'memory',
reader: {
type: 'json',
}
}
});Now when I run the application it remains blank :( nothing in the console
For example, I'm using the storeId in the controller, is this correct ?
Do you have other suggestions ?

thanks a lot

mitchellsimoens
17 Jan 2012, 7:32 AM
You extend Ext.data.Store and your class name should be Data.store.users (note that users should really be capitalized, you would need to change this in the controller as well)

jeanluca
17 Jan 2012, 8:19 AM
thats it, thanks a lot!!

I really like Sencha Touch, but the errors (or blank screen) are very hard to debug!

cheers

mitchellsimoens
17 Jan 2012, 8:27 AM
What JS file are you using? sencha-touch-debug.js should give you some errors and call stacks that help you plus the understanding of the MVC pattern will be better as the next release there will be more tutorials.

jeanluca
17 Jan 2012, 1:24 PM
ok, I'm using sencha-touch-all-uncompressed-w-comments.js
Thnx for the tip!