PDA

View Full Version : Loading a store, from a hasMany



Scott-1
18 May 2015, 12:50 PM
This is my Model

Ext.define('LT.model.PublishAudit', {
extend: 'Ext.data.Model',


idProperty: 'id',
fields: [
{name: 'id', type: 'int'},
{name: 'description', type: 'string'},
{name: 'initializeFlag', type: 'boolean'},
{name: 'message', type: 'string'},
{name: 'targetEnvironments', type: 'string'},
{name: 'publishErrors', type: 'string'},
{name: 'createdBy', type: 'string'},
{name: 'dateCreated', type: 'date'},
{name: 'itemCount', type: 'int'},
{name: 'relatedItemCount', type: 'int'}
],


hasMany: [
{
model: 'LT.model.ItemShort',
name: 'items',
associationKey: 'items',
foreignKey: 'id',
proxy: {
type: 'rest',
url: 'publish/getItems',
reader: {
type: 'json',
root: 'data'
}
}
},
{model: 'LT.model.ItemShort', name: 'relatedItems', associationKey: 'relatedItems', foreignKey: 'id'}
],

proxy: {
type: 'rest',
url: 'publish',
reader: {
type: 'json',
root: 'data'
}
}
});


This is how I would like to load the child associations.

selection.items().load(id, {
scope: this,
callback: function(records, operation, success) {
// TODO: Create shared functionality to do this work.
if ( success && operation.serverResponse && operation.serverResponse.responseText ) {
var decodedResponseData = Ext.decode(operation.serverResponse.responseText);
console.log('Success');
}
}
});


I have a master grid that will have several 100 records loaded, plus under each item there may be 100's records as well. This is taking to long to load in production, so I need to break this into two calls 1 to load the master store and when clicked on in the grid; load the hasMany association of the master record. I would prefer to load them into the child and be able to check this to only load once even if clicked multiple times.

Right now the way it is configured, I am getting an error saying the URL is not defined.

jdkhamba
19 May 2015, 9:25 AM
Probably the store is getting loaded in the browser before the model has a chance to be instantiated. Make sure the order in which they are defined and created are correct