Monday, 9 September 2013

Extjs 4 , how to insert into a record with association into a record

Extjs 4 , how to insert into a record with association into a record

This is the first model define
Ext.define('manage.model.Store', {
extend: 'Ext.data.Model',
requires: [
'manage.model.User'
],
fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'address', type: 'string' },
{ name: 'phone', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'createDate', }
],
belongsTo: [{ model: 'manage.model.User' ,associationKey : 'manager',
name : 'manager' , getterName:'getmanager'}]
});
This is the second model define
Ext.define('manage.model.User', {
extend: 'Ext.data.Model',
fields:[
{name:'id',mapping:'id'},
{name:'username',mapping:'username'},
{name:'employeeName',mapping:'employeeName'},
{name:'birthday',mapping:'birthday'},
{name:'sex',mapping:'sex'},
{name:'mobile',mapping:'mobile'},
{name:'email',mapping:'email'},
{name:'accountCreateDate',mapping:'accountCreateDate'},
{name:'accountExpireDate',mapping:'accountExpireDate'},
{name:'enabled',mapping:'enabled'},
{name:'received',mapping:'received'},
{name:'lastLogin',mapping:'lastLogin'},
{name:'lastLoginAddress',mapping:'lastLoginAddress'},
] ,
});
This is the code to load the json from server
createStoreForm.form.submit({
waitTitle : 'Please wait',
waitMsg : 'Processing......',
url : server+'data/addStore',
success : function(form, action) {
var result = action.result;
if(result.success){
createStoreWindow.close();
var storeStore = Ext.getStore('StoreStore');
storeStore.insert(0, result.data);
}else{
Ext.Msg.alert('Warning',action.result.message);
createStoreForm.form.reset();
}
},
failure : function(form, action) {
if(action.result){
Ext.Msg.alert('Warning',action.result.message);
}else{
Ext.Msg.alert('Warning','Fatal Error');
createStoreForm.form.reset();
}
}
});
}
The json content from server is :
{ "data" : { "address" : "test1",
"createDate" : 1378740195075,
"description" : "test1",
"id" : "297ed0d0410320da01410351cf030003",
"manager" : { "accountCreateDate" : 1378736879000,
"accountExpireDate" : null,
"birthday" : 1378736879000,
"email" : null,
"employeeName" : "administrator",
"enabled" : true,
"id" : "297ed0d041031f1f0141031f373d0001",
"lastLogin" : 1378739298000,
"lastLoginAddress" : "127.0.0.1",
"mobile" : null,
"received" : false,
"sex" : 1,
"username" : "deadpang"
},
"name" : "test1",
"phone" : "12345678"
},
"message" : null,
"success" : true
}
But the new record in the store is not I want When I call getmanager , all
the fields in getmanager().data is empty , so that I can not make the
manager name to be shown in the grid What confused me is when I reload all
the records from server , all the problems are gone. This only happens
when I post form to create new record and insert into store.

No comments:

Post a Comment