ExtJs 4 - Load nested data on record save

我们两清 提交于 2019-12-02 07:06:30

问题


I have two Models. Master -

Ext.define('App.model.Master', {
   extend    : 'Ext.data.Model'

  ,fields    : [
    { name  : 'master_name', type  : 'string' },
    { name  : 'id', type  : 'int'}
  ]
  ,proxy    : {
    type  : 'rest',
    url    : '/master',
    reader    : {
      type  : 'json',
      root  : 'masters'
    }
  }
  ,associations  : [{
    type      : 'hasMany'
    id        : 'id',
    foreignKey    : 'master_id',
    associationKey  : 'details',
    name      : 'details',
    model      : 'App.model.Detail',
  }]
});

and Detail -

Ext.define('App.model.Detail', {
  extend    : 'Ext.data.Model'
  fields    : [
    { name  : 'detail_name', type  : 'string' },
    { name  : 'id', type  : 'int' },
    {name  : 'master_id', type  : 'string'}
  ]
});

My problem is, when I add a new Master record, there is a Detail that is added automatically in the Server. And the response that I get is -

{
  success : true,
  masters : {
    master_name  : 'aaa',
    id      : 1,
    details    : [
      {
        detail_name  : 'bbb',
        id      : 11,
        master_id  : 1
      }
    ]
  }
}

Despite all my efforts, I'm not able to read the 'detail', once the response is added into the Master Store. I would think that the 'record.details()' would give me the one record that came back on adding of the Master, but I get nothing.

However, if I reload the store, I'm able to get the data correctly.

I need to be able to read the nested response on Store.add() as well.

Any help is much appreciated.

来源:https://stackoverflow.com/questions/13828092/extjs-4-load-nested-data-on-record-save

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!