ExtJS Model - Combine Fields

Is there a reasonable way in a model to combine 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 tried many ways, but I can not get them to work.

I was going to use the function in the model to combine the two fields together, but I also need to use this as a display field inside an itemselector (custom control) element and switch it dynamically, and this control does not look like 'FullName ()' as a display field .

Any thoughts were greatly appreciated.

+6
source share
1 answer

Use the convert configuration of the Ext.data.Field parameter: 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 is a live example: https://fiddle.sencha.com/#fiddle/mf

+10
source

Source: https://habr.com/ru/post/954685/


All Articles