PDA

View Full Version : [BIG WONDER BUG EXTJS 4.2] Same key [ID] when update 1 record in Grid panel



hoaibaotre
18 Sep 2013, 6:06 PM
Dear all,

I don't know why this problem has been raised in EXTJS 4.2. And I'm very supprise about this.

My snipest likes this: 1 grid displays list of companys; after that, i modify 1 record and submit change. Unfortunatelly, server response 500 status; and I use Firebug for check request parameters I see that my object has 2 properties [ID] and [id].

And i receive exception message "an item with same key has already been added", I debug in my controller, but nothing jump to here.

After, I change my property [ID] to [SSID], then everything is OK and debug point has been jump to.

Thank for help,
HoaND

My environment: Visual studio 2012, MVC4, EXTJS 4.2:


***My store.js
var writer = new Ext.data.JsonWriter({
type: 'json',
encode: false,
listful: true,
writeAllFields: true,
returnJson: true
});

var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'ID',
root: 'Data',
messageProperty: 'message'
});

var proxy = new Ext.data.HttpProxy({
reader: reader,
writer: writer,
type: 'ajax',
api: {
read: '/SaCompany/Get',
create: '/SaCompany/Create',
update: '/SaCompany/Update',
destroy: '/SaCompany/Delete'
}




***My model.js
Ext.define('Gtrack.model.SaCompanyModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'ID'
},
{
name: 'COMPANY_NAME'
},
{
name: 'COMPANY_ALIAS'
},
{
name: 'ADDRESS'
},
{
name: 'GROUP_ID'
},
{
name: 'AGENT_ID'
},
{
name: 'DESCRIPTION'
},
{
name: 'FAX'
},
{
name: 'EMAIL'
},
{
name: 'WEBSITE'
},
{
name: 'PHONE'
},
{
name: 'SLOGAN'
},
{
name: 'LOGO'
},
{
name: 'REPR_NAME'
},
{
name: 'REPR_TEL'
},
{
name: 'REPR_MAIL'
},
{
name: 'USER_COUNT'
},
{
name: 'MESS_LONG'
},
{
name: 'IMG_LONG'
},
{
name: 'FREE_SMS'
},
{
name: 'CHANGE_SMS'
},
{
name: 'IS_ACTIVE'
},
{
name: 'IS_DELETE'
},
{
name: 'CREATOR'
},
{
name: 'MODIFIER'
},
{
name: 'MODIFY_TIME'
},
{
name: 'CREATE_TIME'
}
]
});






***My controller.js
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
//record.set(values);
form.updateRecord(form.getRecord());
win.close();

//win.callback = Ext.bind(this.contactEdited, this);

var store = Ext.data.StoreManager.lookup('SaCompanyStore');
store.sync({
callback: function (batch, options) {
alert(1);
},
success: function (batch, options) {
alert(2);
},
failure: function (batch, options) {
console.log("failure");
console.log(batch.operations[0]);
//console.log(batch.operations[0].request.action);
//console.log(batch.operations[0].response.result);
console.log(batch.operations[0].getError());
alert(batch.operations[0].request.action);
// alert(batch.operations[0].response.result);
alert(batch.operations[0].getError());
store.rejectChanges();
alert(4);
}
});






***SERVER CODE

public JsonResult Get(int? start, int? limit, string filter)
{
start = start.HasValue ? start.Value : 0;
limit = limit.HasValue ? limit.Value : Int32.MaxValue;
int cnt = 0;
List<HoaNDTest> lstHoaND = new List<HoaNDTest>();
lstHoaND.Add(new HoaNDTest() {
ID = 10,
COMPANY_NAME="hoand 10",
COMPANY_ALIAS="alias 10"
});
lstHoaND.Add(new HoaNDTest()
{
ID = 15,
COMPANY_NAME = "hoand 15",
COMPANY_ALIAS = "alias 15"
});
lstHoaND.Add(new HoaNDTest()
{
ID = 20,
COMPANY_NAME = "hoand 20",
COMPANY_ALIAS = "alias 20"
});

return Json(new
{
Data = lstHoaND,
total = lstHoaND.Count
}, JsonRequestBehavior.AllowGet);
}

[HttpPost]
public JsonResult Update(SA_COMPANY data)
{
bool success = false;
string message = "no record found";

if (data != null)
{
success = true;
message = "Update method called successfully";
}

return Json(new
{
data,
success,
message
});
}




***My POCO

public class HoaNDTest
{
public long ID { get; set; }
public string COMPANY_NAME { get; set; }
public string COMPANY_ALIAS { get; set; }
public string ADDRESS { get; set; }
public long GROUP_ID { get; set; }
public long AGENT_ID { get; set; }
public string DESCRIPTION { get; set; }
public string FAX { get; set; }
public string EMAIL { get; set; }
public string WEBSITE { get; set; }
public string PHONE { get; set; }
public string SLOGAN { get; set; }
public string LOGO { get; set; }
public string REPR_NAME { get; set; }
public string REPR_TEL { get; set; }
public string REPR_MAIL { get; set; }
public Nullable<long> USER_COUNT { get; set; }
public Nullable<long> MESS_LONG { get; set; }
public Nullable<long> IMG_LONG { get; set; }
public Nullable<long> FREE_SMS { get; set; }
public Nullable<long> CHANGE_SMS { get; set; }
public short IS_ACTIVE { get; set; }
public short IS_DELETE { get; set; }
public string CREATOR { get; set; }
public string MODIFIER { get; set; }
public Nullable<long> MODIFY_TIME { get; set; }
public Nullable<long> CREATE_TIME { get; set; }
}



Extjs 4.2: generate [id] field and my [ID] field

45887

Extjs 4.0: no generate [id] field
45888

ettavolt
18 Sep 2013, 10:55 PM
idProperty is a config for model, not reader.

hoaibaotre
19 Sep 2013, 12:56 AM
It's OK.

Thank Ettavol.