PDA

View Full Version : [OPEN] [CLOSED][3.??] the jsonreader bug (this.getId()) when created by JsonStore.



arron
3 Sep 2009, 5:34 AM
all code:

var writer = new Ext.data.JsonWriter( {
writeAllFields : false,
id : 'j_id21'
});
var reader = new Ext.data.HttpProxy( {
url : '/fenceweb/faces/editgridpanel.xhtml',
id : 'j_id42'
});
var store1 = new Ext.data.JsonStore( {
totalProperty : 'total',
baseParams : {
"Ext_AJAX" : "true",
"Ext_Handler" : "storeHandler",
"Ext_Render" : "store1",
"Ext_Immediate" : "true"
},
successProperty : 'success',
fields : [ {
name : 'id'
}, {
name : 'username'
}, {
name : 'password'
}, {
name : 'birthDate'
} ],
proxy : j_id42,
id : 'store1',
idProperty : 'username',
data : {
"total" : 10,
"data" : [ {
"age" : 0,
"birthDate" : {
"date" : 3,
"day" : 4,
"hours" : 21,
"minutes" : 23,
"month" : 8,
"seconds" : 1,
"time" : 1251984181989,
"timezoneOffset" : -480,
"year" : 109
},
"childs" : [],
"hasCar" : false,
"id" : 100,
"password" : "p:27",
"salary" : 7000,
"sex" : 1,
"username" : "u:0",
"wife" : null
},{
"age" : 9,
"birthDate" : {
"date" : 3,
"day" : 4,
"hours" : 21,
"minutes" : 23,
"month" : 8,
"seconds" : 1,
"time" : 1251984181989,
"timezoneOffset" : -480,
"year" : 109
},
"childs" : [],
"hasCar" : false,
"id" : 109,
"password" : "p:57",
"salary" : 3000,
"sex" : 1,
"username" : "u:9",
"wife" : null
} ],
"success" : true,
"viewState" : "j_id11:j_id12"
},
xtype : 'jsonstore',
root : 'data',
writer : j_id21,
autoSave : false
});

when store1.save(),the request always use xaction create.I thank it's a bug in JsonReader:

// private
buildExtractors : function() {
if(this.ef){
return;
}
var s = this.meta, Record = this.recordType,
f = Record.prototype.fields, fi = f.items, fl = f.length;

if(s.totalProperty) {
this.getTotal = this.getJsonAccessor(s.totalProperty);
}
if(s.successProperty) {
this.getSuccess = this.getJsonAccessor(s.successProperty);
}
this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
if (s.id || s.idProperty) {
var g = this.getJsonAccessor(s.id || s.idProperty);
this.getId = function(rec) {
var r = g(rec);
return (r === undefined || r === "") ? null : r;
};
} else {
this.getId = function(){return null;};
}
var ef = [];
for(var i = 0; i < fl; i++){
f = fi[i];
var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
ef.push(this.getJsonAccessor(map));
}
this.ef = ef;
},

The red part,If the jsonreader created by the JsonStore,the s.id == store.id; and the this.getId(res) always get undefined. Even idProperty setting. so the modify record always created.

arron
3 Sep 2009, 5:47 AM
if we use the Store and A JsonReader, we can't config a 'id' config to JsonReader,

Condor
3 Sep 2009, 6:00 AM
The store id config option is deprecated (exactly because of this problem).

You should use the storeId config option instead.

evant
3 Sep 2009, 10:04 PM
Agree with Condor. Marking this as closed.