I'm setting 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 set somehow an idProperty for these fields direct in the store ? The only option I see is to create a separate model class containing a idProperty. But I'd like to avoid this.
The default id Property is id
. You can change it either on the model or the reader of the proxy.
Note: the store can use the proxy of the model (not done 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
});
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