PDA

View Full Version : Ext.getStore returning null



jiewmeng
22 May 2012, 2:02 AM
In my controller, I am trying to add an object/model into my LocalStorage store:


Ext.define('SimpleTodo.controller.ProjectsController', {
extend: 'Ext.app.Controller',
refs: [
{ ref: 'addProjectPanel', selector: '#addProjectPanel' }
],
init: function() {
this.control({
'button[action=addProject]': {
click: this.addProject
}
});
},
addProject: function() {
console.log('Done!');
var form = this.getAddProjectPanel().getForm();
if (form.isValid()) {
var projectsStore = Ext.getStore('projects');
projectsStore.add(form.getFieldValues());
projectsStore.sync();
} else {
Ext.Msg.alert('INVALID!');
}

}
});


But the store is always null, I believe its not initalized yet or something? In another controller I was able to solve that moving that into launch instead of init. Here that doesn't appear to work. My store was defined like


Ext.define('SimpleTodo.store.Projects', {
extend: 'Ext.data.Store',
requires: [
'SimpleTodo.model.Project'
],
model: 'SimpleTodo.model.Project',
storeId: 'projects'
});


and model:


Ext.define('SimpleTodo.model.Project', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
{ name: 'description', type: 'string' }
],
validations: [
{ field: 'name', type: 'presence' },
{ field: 'name', type: 'length', max: 64 },
{ field: 'name', type: 'format', matcher: /[a-zA-Z0-9-_.]+/ },
{ field: 'description', type: 'length', max: 512 }
],
hasMany: [
{ model: 'SimpleTodo.model.TodoList', name: 'todoLists' }
],
proxy: {
type: 'localstorage',
id: 'projects'
}
});

scottmartin
23 May 2012, 6:57 AM
I would make the following changes to be mode consistent:



Ext.define('SimpleTodo.controller.ProjectsController', {
extend: 'Ext.app.Controller',
stores: ['Projects'],
refs: [
{ ref: 'addProjectPanel', selector: '#addProjectPanel' }
],
..

var projectsStore = Ext.getStore('Projects');





Ext.define('SimpleTodo.store.Projects', {
extend: 'Ext.data.Store',
// storeId: 'projects'
});


and remove id: 'projects' from your proxy.

Regards,
Scott.