加载与gridpanel关联的商店时出错

时间:2013-11-15 05:56:52

标签: extjs sencha-touch

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!!');
}

//商店     Ext.define('MyApp.store.userStore',{     extend:'Ext.data.Store',     别名:'store.userStore',     要求:[     'MyApp.model.User'     ]     构造函数:function(cfg){     var me = this;     cfg = cfg || {};     me.callParent([Ext.apply({     autoLoad:true,     autoSync:true,     model:'MyApp.model.User',     storeId:'userStore',     代理: {     输入:'ajax',     读者:{     类型:'json'     }     }     },cfg)]);     }     });

1 个答案:

答案 0 :(得分:1)

您的代码不正确有两个原因:

1)您不应该修改基础数据集合。如果它给出了错误,那么其他错误。

2)如果您要加载商店,为什么要添加商品?它应该已经加载。