0
votes

I am trying to populate all the records at once in a model and then assign each collective property to different container.

i.e. I have 1 grid and 1 combo on my page and trying both in one call. So I fetch the data successfully but it comes in forms of Nested JSON Data.

Ext.Model ('Person', {
  fields: [
    { name: 'firstname' },
    { name: 'lastname' },
    { name: 'placesOfWork' }
  ],
  associations: [
    { type: 'hasMany', model: 'PlaceOfWork', name: 'placesOfWork' }
});

this is my model class and whenever I try to assign it to grid so first thing I must need to iterate through each property and then create a new store at runtime to assign the data.

First I read the data by using store.reader.JsonData.placesOfWork which returns me a jsonArray and then create a store using the array elements.

Problem is not this as I got my data in grid and combo. But whenever I try to get my grid and store or comboValue then it always returns me null or store size "0"

var grid = Ext.getCmp("MyGRidID");
var store = grid.getStore();
alert(store.getCount());

It returns me 0 while data is available in my grid. similar thing happen when I try to get value from my combo which was dynamically bonded.

    var combo = Ext.getCmp("MyCombo");
    var value = combo.getValue();
    var rawValue = combo.getRawValue();

alert(value);
alert(rawValue);

Both returns null and empty value.

1

1 Answers

0
votes

You do extraneous manual work that is not necessary. First of all read Loading Nested Data in the Ext documentation. Then, you should have two models, proper reference between them and you should return correct JSON string from the server.

Then it's easy, you do not need to create and populate the many store manually, Ext does it for you. Also, Ext creates accessor function placesOfWork() that you can call to get the reference to the many store.