PDA

View Full Version : Loading stores dynamically



missett
18 Feb 2013, 2:19 PM
Hi All,

I'll try to keep this as non-specific to my project as possible so others can use it. I've created a hierarchy of models that relate to each other using the association configs (ie. hasMany, belongsTo etc.). I'm confident this is all configured properly because I can access the children of the root node using the auto-generated getters and they all return the data I would expect from my nested JSON. I'm now trying to use this data in some combobox components. So combobox A would contain data from the root node, combobox B would contain data from the children of the root, and so on and so on. However I'm unsure of the best way to do this.

At the minute my approach is to give all the comboboxes stores that reference the models with the data. The problem now is that the only store that gets populated is the root store (store A/model A/combobox A) and it displays the values in the combobox. The strange thing is that I can get a reference to this model and call the generated getter methods and get back the expected data- but the comboboxes don't display the data. And when I get a reference to the stores through the comboboxes using getStore() they have no data in them.

Would the right approach be to use the root store and get the child model elements using the generated getter methods, then add them to the other stores manually? Or have I missed something somewhere?



var newStore = Ext.create('Ext.data.Store', {
model: 'MyModel'
});


newStore.load({
callback: function(records, operation, success) {
var first = newStore.first();
console.log(first.get('name'));
first.bGroups().each(function(group) {
console.log('\t' + group.get('name'));


group.lEntities().each(function(le) {
console.log('\t\t' + le.get('name'));


le.nostros().each(function(nostro) {
console.log('\t\t\t' + nostro.get('name') + ' ' + nostro.get('currency'));
});
});
});
}
});


For reference this is the code I can use to access the model hierarchy.

UPDATE

Ok, so I've put this code in place to load a store dynamically. When it gets run, the comboxbox displays the right values but it also greys them out and puts a loading mask over the top of them like it's still trying to load things (all the expected values are there). We also get the generic error 'cannot call method indexOf of undefined'.



bGroup.getStore().load({
callback: function(records, operation, success) {
console.log(bGroup.getStore());
console.log(busGroup.getStore());


var busGroupsArray = records[0].busGroups().getRange();
busGroup.getStore().loadRecords(busGroupsArray);
}
});


Any more thoughts?

UPDATE

To get the loading mask to stop showing all the time, adding 'queryMode: 'local'' to the combobox config seems to have done the trick. I could still use some feedback about whether this is the right approach to be taking for this anyway, hopefully it'll be useful to people.

scottmartin
20 Feb 2013, 11:59 AM
You would need to show your models, stores and data for anyone to help.

Have you inspected the store to see if the data has arrived, or just not populating the combo?
Are you mapping the fields to access the correct level?

Scott.