Extjs adds idproperty to fields defined in the repository

I set my fields directly in the store configuration.

Ext.define('T.store.Users', { extend: 'Ext.data.Store', autoLoad: false, fields: [ { name: 'Id', type: 'int' }, { name: 'Name', type: 'string' } ] }); 

Is it possible to somehow set idProperty for these fields directly in the repository? The only option I see is to create a separate model class containing idProperty. But I would like to avoid this.

+4
source share
2 answers

Theoretically, you can change idProperty inside the constructor as follows:

 Ext.define('T.store.Users', { extend: 'Ext.data.Store', autoLoad: false, constructor: function(){ this.callParent(arguments); this.model.prototype.idProperty = 'Id'; }, fields: [ { name: 'Id', type: 'int' }, { name: 'Name', type: 'string' } ] }); 
+4
source

The default identifier is id . You can change it either on the model or on the proxy reader.

Note. The repository may use a proxy model of the model (not specified in this example).

Example (with both)

 // Set up a model to use in our Store Ext.define('User', { extend: 'Ext.data.Model', idProperty: 'Id', fields: [ {name: 'firstName', type: 'string'}, {name: 'lastName', type: 'string'}, {name: 'age', type: 'int'}, {name: 'eyeColor', type: 'string'} ] }); var myStore = Ext.create('Ext.data.Store', { model: 'User', proxy: { type: 'ajax', url: '/users.json', reader: { type: 'json', root: 'users', idProperty: 'Id' } }, autoLoad: true }); 
+14
source

All Articles