PDA

View Full Version : Created class has default values instead of undefined



ipavlic
12 Oct 2012, 4:17 AM
I have an entity defined like this:

Ext.define('MyApp.model.Entity', { extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int'
} ]
});

If I instantiate it and look at the id, it will have a default value of 0:


var entity = Ext.create('MyApp.model.Entity');
console.log(entity.getId()); //will output '0' instead of 'undefined'

Is this expected behaviour? Why?

vietits
12 Oct 2012, 4:55 AM
That is default behaviour of field with 'int' type. If you want default value is null instead of 0, try to set useNull to true. See more here http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Field-cfg-useNull.


Ext.define('MyApp.model.Entity', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int',
useNull: true
}]
});