PDA

View Full Version : Why store is not loading?



darkhorni
24 Feb 2015, 3:14 PM
I have Main.js


/**
* This class is the main view for the application. It is specified in app.js as the
* "autoCreateViewport" property. That setting automatically applies the "viewport"
* plugin to promote that instance of this class to the body element.
*
* TODO - Replace this content of this view to suite the needs of your application.
*/
Ext.define('Contacts.view.main.Main', {
extend: 'Ext.container.Container',
requires: [
'Contacts.view.main.MainController',
'Contacts.view.main.MainModel',
'Contacts.store.Contacts'
],

xtype: 'app-main',

controller: 'main',
viewModel: {
type: 'main'
},

layout: {
type: 'border'
},

items: [{
region: 'north',
xtype: 'component',
cls: 'appBanner',
padding: 10,
height: 40,
html: 'My Company - My Company Motto'
},{
xtype: 'panel',
bind: {
title: '{name}'
},
region: 'west',
html: '<ul><li>This area is commonly used for navigation, for example, using a "tree" component.</li></ul>',
width: 250,
split: true,
collapsible: true,
tbar: [{
text: 'Button',
handler: 'onClickButton'
}]
},{
region: 'center',
xtype: 'tabpanel',
items:[{
title: 'Tab 1',
html: '<h2>Content appropriate for the current navigation.</h2>'
},{
title: 'The Data',
layout: 'fit',
id: 'ilhanGrid',
items: [{
xtype: 'grid',
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1},
{ text: 'ID', dataIndex: 'id' }
]
}]
}]
}]
});

and Contacts.js


Ext.define('Contacts.store.Contacts', {
extend: 'Ext.data.Store',
model: 'Contacts.model.Contacts',
autoLoad: true,
storeId:'simpsonsStore',
id: 'ilhan',
alias: 'store.simpsonsStore',
proxy: {
type: 'ajax',
api: {
// These are static JSON files that never change. In a real system
// they will normally point to a page that gets processed on the server.
read: 'app/data/users.json',
update: 'app/data/updateUsers.json'
},
reader: {
type: 'json',
rootProperty: 'users',
successProperty: 'success'
}
},
listeners: {
load: function(store, records) {
console.log(records)
}
}
});

However although I have set autoLoad to true the data is not loading. What I'm missing? These codes are from the examples and according to the documentation I can associate them with storeId.

evant
24 Feb 2015, 3:38 PM
In the code you posted you never create an instance of the store. Even if you did have an instance, you're relying on the timing of it being created because you're attempting to assign it at definition time.

darkhorni
25 Feb 2015, 2:34 PM
In the code you posted you never create an instance of the store. Even if you did have an instance, you're relying on the timing of it being created because you're attempting to assign it at definition time.

Thanks for the response. So I have found an example about Books store and it appears that this code solves my problem:


},{
title: 'The Data',
layout: 'fit',
id: 'ilhanGrid',
items: [{
xtype: 'grid',
title: 'Simpsons',
store: {
type: 'simpsonsStore' // <----------------------
},