PDA

View Full Version : [CLOSED]'id' added to JSonReader leads to unexpected behaviour on updating



Pachat
13 Jun 2010, 12:07 AM
I methodically added id to all the objects.
Example :

var reader_members = new Ext.data.JsonReader({
id: 'id-reader_members',Then, when updating, id: 0 is transmitted as the value within the row

{"success":true,"rows":"{\"id\":0,\"name\":\"Smith\""}and the associated action is 'create' instead of 'update'.

Of course, I removed
id: 'id-reader_members',

But the time it took to find this behaviour makes consider this as a bug :
Adding id: 'id-reader_members', should have been neutral and not disturb the xaction.

ExtJS 3.2.1

evant
13 Jun 2010, 12:12 AM
This is the expected behaviour. If you give the record an explicit id, it will be treated as though it exists. Assign an empty id if you want it to be treated as a record that doesn't exist on the server.

Pachat
13 Jun 2010, 12:31 AM
The record has 'id' as its first field and therefore exists on the server :

var record_members = Ext.data.Record.create([
{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}
]);
May be my mistake is that I did not expect

id: 'id-reader_members'to interfer with the 'id' within the fields

Here is the complete Reader :


var reader_members = new Ext.data.JsonReader({
id: 'id-reader_members', //leads to "id":0 within fields
root: 'rows',
idProperty: 'id',
successProperty: 'success',
fields: record_members
});

Condor
13 Jun 2010, 6:39 AM
The 'id' config option of JsonReader is deprecated, because it is used as both the 'idProperty' and the 'storeId' (which are the properties you should actually be using).