PDA

View Full Version : MemoryProxy me.model is undefined error



talha06
26 May 2012, 1:55 PM
Hello everyone,

I'm getting an error like I added below while using static data with memory proxy.
Can someone show me my mistake or missing part?

Thanks in advance.


me.model is undefined
me.setProxy(me.proxy || me.model.getProxy());


My model definition:

Ext.define(appName + '.model.Country', { extend: 'Ext.data.Model',
fields: [
{type: 'string', name: 'abbr'},
{type: 'string', name: 'name'},
{type: 'string', name: 'slogan'}
]
});

And here's my store definition:

// The data for all states
var data = {
states : [
{'abbr':'AL','name':'Alabama','slogan':'The Heart of Dixie'},
{'abbr':'AK','name':'Alaska','slogan':'The Land of the Midnight Sun'}
]
};


Ext.define(appName + '.store.Countries', {
extend : 'Ext.data.Store',
model : appName + '.model.Country',
data : data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'states'
}
}
});

vietits
26 May 2012, 3:29 PM
Which Ext version do you use? I have tried to run your code with Ext 4.1.0, Chrome 19 and encountered no problem.


Ext.onReady(function(){
var appName = 'App';
Ext.define(appName + '.model.Country', {
extend: 'Ext.data.Model',
fields: [
{type: 'string', name: 'abbr'},
{type: 'string', name: 'name'},
{type: 'string', name: 'slogan'}
]
});


// The data for all states
var data = {
states : [
{'abbr':'AL','name':'Alabama','slogan':'The Heart of Dixie'},
{'abbr':'AK','name':'Alaska','slogan':'The Land of the Midnight Sun'}
]
};


Ext.define(appName + '.store.Countries', {
extend: 'Ext.data.Store',
model : appName + '.model.Country',
data : data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'states'
}
}
});


var store = Ext.create(appName + '.store.Countries');
console.log(store)
});

skirtle
26 May 2012, 5:57 PM
Is the file defining your model definitely included in your page? If you're using dynamic loading you'll need to include the model as a requires on your store, they aren't currently implicit.

If you're using a suitable debug version of the library (either dynamic loading or ext-all-dev.js) you should see warning messages about the model not being configured correctly.

talha06
27 May 2012, 2:16 AM
@vietits,
I'm using Ext JS 4.1.0.

@skirtle,
I'm using dynamic loading, I've included ext-all-debug, it just says the error I mentioned above with message "Store defined with no model. You may have mistyped the model name.". I've many stores that have same config; but all others are ajax proxy.

Thanks for your interest and care.
Regards.

skirtle
27 May 2012, 4:36 AM
Timing matters. The model must be loaded before the store is created. Take a look at the network tab, do you see the model file being loaded?

Try adding a requires block to the store to include the model.

talha06
27 May 2012, 4:50 AM
Timing matters. The model must be loaded before the store is created. Take a look at the network tab, do you see the model file being loaded?

Try adding a requires block to the store to include the model.
still gives same error despite I added requires config and also Ext.require(..) function at the top of the store script.
By the way model Country is loaded before than Countries store.(as it's shown at the screenshot) :-?
35653


Ext.require([
appName + '.model.Country'
]);

Ext.define(appName + '.store.Countries', {
requires : [ appName + '.model.Country' ],
extend : 'Ext.data.Store',
model : appName + '.model.Country',
data : data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'states'
}
}
});

scottmartin
30 May 2012, 6:58 AM
A quick note about your appName. You should be able to set your name in your app and not specify it all over the place. Is your path correct when using your approach?



Ext.application({
name : 'MYAPP',
...
});


Regards,
Scott.

talha06
30 May 2012, 12:22 PM
Yeah it's appName which is imported first.
Thanks for your care & reply..