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',代理:{类型:'ajax',读者:{类型:'json'}}}},cfg)]);}});