PDA

View Full Version : ExtJS 4.2 Model Mapping issue for Boolean fields



aswini.nayak
16 Jul 2015, 6:48 AM
The field defined with "boolean" without defaultValue is causing issue. Its not returning the correct value. Sample code.

Ext.define('Test2', {
extend : 'Ext.data.Model',
idProperty : 'empid',
fields : [{

name : "hasName",
type : "boolean",
mapping : "employeehasName"

}]
});


var obj = Ext.create("Test2",{employeehasName:true});

obj.data.hasName // returns false. It should return true, not sure why its returning false.

obj.raw.employeehasName // returns true

Is this a mapping issue. Why its changing the value from "true" to "false"? Anyone have experienced this. I don't want to set the "defaultValue". Wants to know why this is happening. Thanks in advance!!!

jdkhamba
17 Jul 2015, 4:35 AM
Could be a bug.It seems to persist in extJS 6 as well. Here is a workaround:


Ext.define('Test2', {
extend : 'Ext.data.Model',
idProperty : 'empid',
fields : [{


name : "hasName",
type : "boolean",
mapping : "employeehasName",
convert:function(v,rec){
return rec.get('employeehasName');
}




}]
});


var obj = Ext.create("Test2",{employeehasName:true,empid:1});




console.log(obj.get('hasName'));