ExtJs 4 - 在记录保存时加载嵌套数据

时间:2012-12-11 20:35:39

标签: extjs4.1

我有两个型号。大师 -

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',
  }]
});

和细节 -

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

我的问题是,当我添加新的主记录时,会在服务器中自动添加一个详细信息。我得到的回应是 -

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

尽管我付出了很多努力,但一旦将响应添加到Master Store中,我就无法读取“详细信息”。我会认为'record.details()'会给我一条记录,在添加Master时会回来,但我什么都没得到。

但是,如果我重新加载商店,我就能正确获取数据。

我也需要能够在Store.add()上读取嵌套响应。

非常感谢任何帮助。

0 个答案:

没有答案