Is there a sensible way in a model to concatenate two fields, something like this:
Ext.define('model.Person', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{ name: 'FullName', type: 'string', mapping: 'FirstName + " " + LastName' }
]
});
I've tried a multitude of ways, but can't seem to get any to work.
I was going to use a function in the model to stick the two fields together, but I also need to use this as the displayfield inside a 'itemselector' (custom control) and switch this dynamically and that control doesn't seem to like 'FullName()' as a displayfield.
Any thoughts greatly appreciated.
Use the convert
config of the Ext.data.Field: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Field-cfg-convert
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{
name: 'FullName',
type: 'string',
convert: function( v, record ) {
return record.get( 'FirstName' ) + ' ' + record.get( 'LastName' )
}
}
Here's a live example: https://fiddle.sencha.com/#fiddle/mf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With