I'm going through a Sencha tutorial and I'm receiving this error when attempting to implement a store in my app. I'm sure this is something simple I'm overlooking but I'm having trouble figuring out what it is.
applyStore] The specified Store cannot be found
Here is the relevant code:
//from app.js
stores: [
'MyStore'
],
//from the view
Ext.define('listerApp2.view.Main', {
extend: 'Ext.dataview.List',
xtype: 'main',
requires: [
'Ext.TitleBar',
'listerApp2.store.MyStore'
],
config: {
title: 'My listing',
store: 'MyStore'
}
});
//from the store
Ext.define('listerApp2.store.MyStore', {
requires: ['listerApp2.model.MyModel'],
config: {
autoload: true,
model: 'MyModel',
storeId: 'MyStore',
alias: 'store.MyStore',
data: [
{firstName: 'Washington', lastName: 'George', age: 250},
{firstName: 'Lincoln', lastName: 'Abe', age: 200},
{firstName: 'Clinton', lastName: 'Bill', age: 60}
],
proxy: {
type: 'localStorage'
}
}
});
//and the model
Ext.define('listerApp2.model.MyModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'firstName', type: 'string' },
{ name: 'lastName', type: 'string' },
{ name: 'age', type: 'int' }
]
}
});
You have mixed up many things in your code. For e.g. you have used localStorage
and storeId
which are not making any sense here. I have simplified your code and pasting here:
Model
Ext.define('MyApp.model.DataModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'firstName', type: 'string' },
{ name: 'lastName', type: 'string' },
{ name: 'age', type: 'int' }
]
}
});
Store
Ext.define('MyApp.store.DataStore', {
extend: 'Ext.data.Store',
config: {
model: 'MyApp.model.DataModel',
autoLoad: true,
data: [
{firstName: 'Washington', lastName: 'George', age: 250},
{firstName: 'Lincoln', lastName: 'Abe', age: 200},
{firstName: 'Clinton', lastName: 'Bill', age: 60}
]
}
});
View
Ext.define('MyApp.view.HobbyList', {
extend: 'Ext.List',
xtype: 'hobbyList',
requires: [
'Ext.dataview.List'
],
config: {
styleHtmlContent : true,
itemTpl : new Ext.XTemplate(
'{firstName} {lastName} is {age} years old.'
),
store: 'DataStore'
}
});
I have tested this. It is working fine. Take a look.
Happy Coding!