2
votes

I have a TreeStore, which works fine, but every node has some nested data, so I made a new model for it and used the hasMany association. But now the store loads nothing anymore. When I look into the records in the load event, they're empty, but the browser tells me the Ajax request delivered everything like before.

This is what the node data looks like, when it comes from the server:

{
  "path": "KEY_518693",
  "name": "KEY_518693",
  "data": [
    {
      "branch": "KEY_518693",
      "primnav": "ETC",
      "X": 29261,
      "Y": 96492
    },
    ...
  ],
  "children": [ ... ],
  ...
}

These are my model definitions:

TreeNode:
{
  extend  : 'Ext.data.Model',
  requires: [
    'DataRecord',
    'Ext.data.association.HasMany'
  ],
  fields  : [
    { name: 'id'  , type: 'string', mapping: 'path' },
    { name: 'text', type: 'string', mapping: 'name' },
    ...
  ],
  hasMany : {
    model: 'DataRecord',
    name : 'data'
  }
DataRecord:
{
  extend: 'Ext.data.Model',
  fields: [
    { name: 'branch' , type: 'string'},
    { name: 'primnav', type: 'string' },
    { name: 'X'      , type: 'int' },
    { name: 'Y'      , type: 'int' }
  ]
}

When I remove the association, the tree loads without problems. When I add data to the fields it gets parsed into the tree, but as "raw" object and not as model instance.

2
As first step to solve this issue, please note that DataRecord has no field called treenode_id - so your hasMany association isn't complete. See docs for more info.Izhaki
Oh yes, I saw it. after I made primaryKey: 'branch' it worked. Also I had an error with the name, which should not be dataK..
yes, after setting the name, the records got loaded again and after setting the primaryKey they were filled with the parsed data.K..

2 Answers

2
votes

Please note that DataRecord has no field called treenode_id - so your hasMany association isn't complete. See docs for more info.

0
votes

My approach had 2 problems.

  1. The name of the association should not be 'data' or the records wont get loaded at all.
  2. The primaryKey of the association has to be set right, in my case 'branch' was right