Models
1. User Model
2. Phone Model
On Save Button Click
Chrome capture post header like
But on asp web api post method it shows only Age, Email and Name but Phone.Count() = 0
Issue with Post: Model have one to many association.
1. User Model
Code:
Ext.define('UserApp.model.User', { extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Integer'
],
uses: [
'UserApp.model.Phone'
],
idProperty: 'Id',
fields: [
{
type: 'int',
name: 'Id'
},
{
name: 'Name'
},
{
name: 'Email'
},
{
type: 'int',
name: 'Age'
},
{
name: 'Phone',
reference: 'UserApp.model.Phone'
}
]
});
2. Phone Model
Code:
Ext.define('UserApp.model.Address', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Integer'
],
idProperty: 'Id',
fields: [
{
type: 'int',
name: 'Id'
},
{
name: 'Address1'
},
{
name: 'Address2'
}
]
});
On Save Button Click
Code:
var user = this.getViewModel().get('VMObj.User');
var Address = this.getViewModel().get('VMObj.Address');
var modelUser = Ext.create('UserApp.model.User');
modelUser.set(user);
modelUser.set('Address', Address);
var store = Ext.getStore('PhoneStore');
var array = Ext.Array.pluck(store.data.items, 'data');
modelUser.set('Phone',array);
var userStor = Ext.getStore('UserJsonStore');
userStor.insert(0, modelUser);
userStor.sync();
Chrome capture post header like
- Age: 12
- Email: "test"
- Id: "UserApp.model.User-1"
- Name: "test"
- Phone: [{Id: "UserApp.model.Phone-3", PhoneNumber: "123", id: "126"},…]
- 0: {Id: "UserApp.model.Phone-3", PhoneNumber: "123", id: "126"}
- 1: {Id: "UserApp.model.Phone-2", PhoneNumber: "65413", id: "125"}
- 2: {Id: "UserApp.model.Phone-1", PhoneNumber: "123456", id: "124"}
But on asp web api post method it shows only Age, Email and Name but Phone.Count() = 0
Issue with Post: Model have one to many association.
Aucun commentaire:
Enregistrer un commentaire