Skip to content

Instantly share code, notes, and snippets.

@obenjiro
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save obenjiro/aadb97abcce885b72a9e to your computer and use it in GitHub Desktop.

Select an option

Save obenjiro/aadb97abcce885b72a9e to your computer and use it in GitHub Desktop.
Bringing computable model fields to ExtJS
// All creadits gouse to
// http://flexblog.faratasystems.com/2012/02/07/computed-fields-in-extjs-models-via-convert-functions
Ext.define('Sample.model.User', {
extend: 'Ext.data.Model',
fields: [
{ name:'id', type:'string' },
{ name:'firstName', type:'string' },
{ name:'lastName', type:'string' },
{
name:'fullName',
type:'string',
convert: function (newValue, model) {
return model.get('lastName') + ', ' + model.get('firstName');
}
}
],
set: function(fieldName, value) {
this.callParent(arguments);
if (fieldName === 'firstName' || fieldName === 'lastName') {
this.set('fullName');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment