0
votes
Ext.define('MyApp.controller.Main', {
extend: 'Ext.app.Controller',
models: [
'User'
],
stores: [
'userStore'
],
refs: [
{
ref: 'navigation',
selector: 'navigation'
},
{
ref: 'ContentPanel',
selector: 'ContentPanel'
},
{
ref: 'viewport',
selector: 'viewport'
},
{
autoCreate: true,
ref: 'myForm',
selector: 'MyForm',
xtype: 'MyForm'
},
{
autoCreate: true,
ref: 'usergrid',
selector: 'usergrid',
xtype: 'userGrid'
}
],
onSaveButtonClick(button,e,eopts){ var form1 = this.getMyForm();
if(form1.isValid())
{
var form  = form1.getForm();
user= this.getUserModel().create(
{
firstName: form.findField('firstName').getValue(),
midName: form.findField('midName').getValue(),
lastName: form.findField('lastName').getValue(),
gender: form.findField('gender').getValue(),
age: form.findField('age').getValue(),
buildingName: form.findField('buildingName').getValue(),
street: form.findField('streetName').getValue(),
country: form.findField('country').getValue(),
pinCode: form.findField('pinCode').getValue(),
state: form.findField('state').getValue()
});
debugger;
var store= this.getUserStoreStore();
store.data.add(user);
var List= this.getUsergrid();
List.getStore().load();
var contentPanel = this.getContentPanel();
contentPanel.removeAll(true);
contentPanel.add(List);
form1.close();
alert('Data stored Successfully');
}
else
{
alert('Few Datas are missing!!');
}

//Store Ext.define('MyApp.store.userStore', { extend: 'Ext.data.Store', alias: 'store.userStore', requires: [ 'MyApp.model.User' ], constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callParent([Ext.apply({ autoLoad: true, autoSync: true, model: 'MyApp.model.User', storeId: 'userStore', proxy: { type: 'ajax', reader: { type: 'json' } } }, cfg)]); } });

1

1 Answers

1
votes

Your code is incorrect for 2 reasons:

1) You should not be modifying the underlying data collection. If it's giving an error, then something else is wrong.

2) If you're loading the store, why are you adding items to it? It should already be loaded.