PDA

View Full Version : An additional id field is being added to my json request in extjs 4.1



Anthony.Hall
9 May 2012, 7:51 AM
In my controller i use the "record.save" function. In extjs 4.07 this would send a single record as json. I've notice in 4.1 it now send an array of the record. This is fine as i can update my server controllers to handle an array ( tho would be nice if could specify just single record )

Though my main issue is that i've been receiving the property "Id" twice in my json. Id is a property of my record class. If you look at the below Json you can see that "Id" has been appended to the end of my Json. What is the reason for this?


[{"Id":"f3e7def0-42e6-41c9-a2ba-a04400b7c568","QuotedPrice":"\u00a3500.00","Notes":"","JobQuantity":"0","DeliveryDate":"","ProjectId":"","id":""}]

here is my model ( i removed some of json to make it more readable )

Ext.define('Mis.model.Job', { extend: 'Ext.data.Model',
fields: [
{
mapping: 'Id',
name: 'Id'
}
,
{
mapping: 'Value',
name: 'QuotedPrice'
},
{
mapping: 'Name',
name: 'Name'
},
{
mapping: 'JobType',
name: 'JobType'
},
{
mapping: 'ClientPo',
name: 'ClientPO'
},
{
mapping: 'FilesOver',
name: 'FilesOver'
},
{
mapping: 'PreviousJobId',
name: 'PreviousJobId'
},
{
mapping: 'EstimateValue',
name: 'Estimate'
},
{
mapping: 'SalesContact',
name: 'SalesContact'
},
{
mapping: 'AccountHandler',
name: 'AccountHandler'
},
{
mapping: 'AssemblyTime',
name: 'AssemblyTime'
},
{
mapping: 'DespatchDate',
name: 'DespatchDate'
},
{
mapping: 'ProductionFiles',
name: 'ProductionFiles'
},
{
mapping: 'Notes',
name: 'Notes'
},
{
mapping: 'Quantity',
name: 'JobQuantity'
},
{
mapping: 'DeliveryDate',
name: 'DeliveryDate'
},
{
mapping: 'ProjectId',
name: 'ProjectId'
}
],
proxy: {
type: 'ajax',
url: 'https://www.xxx.localhost/',
api:
{
read: '/Jobs/Read/' + jId,
update: '/Jobs/Update',
create: '/Jobs/Update',
destroy: '/Jobs/Remove'
},
reader: {
type: 'json',
root: 'Jobs',
successProperty: 'success',
totalProperty: 'Total'
}
}
});

vietits
9 May 2012, 4:44 PM
You should define idProperty for the model.


Ext.define('Mis.model.Job', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
....

To allow sending data as single record instead of array, you should set allowSingle to true for proxy writer.