我正在使用extjs 4.1.1中的主从属详细信息页面。
我有一个拥有多个地址模型的Person模型。 (我在EXTJS中配置了关系)
我有一个显示所有人物记录的网格,当我点击一条记录时,我会在另一个网格中显示此人的相关地址。
填充我使用的第二个网格:
var grid2 = this.getAddressList(); //made a reference to this
var store = record.Addresses(); // this gives me the addresses store associated with the person record
...
grid2.reconfigure(store);
现在,当我向人员的地址存储添加地址时,ajax请求将激活到其余服务器。 为了确保extjs还将相关数据发送到服务器,我创建了一个特殊的编写器类(来自extjs论坛的代码)。
Ext.define('Ext.data.writer.DeepJson', {
extend:'Ext.data.writer.Json',
getRecordData:function (record, operation) {
var isPhantom = record.phantom === true,
writeAll = this.writeAllFields || isPhantom,
nameProperty = this.nameProperty,
fields = record.fields,
data = {},
changes,
name,
field,
key;
if (writeAll) {
// This is the branch that has been changed from the original Json Writer
data = record.getData(true);
} else {
changes = record.getChanges();
for (key in changes) {
if (changes.hasOwnProperty(key)) {
field = fields.get(key);
name = field[nameProperty] || field.name;
data[name] = changes[key];
}
}
}
if (isPhantom) {
if (operation && operation.records.length > 1) {
data[record.clientIdProperty] = record.internalId;
}
} else {
data[record.idProperty] = record.getId();
}
return data;
}
});
在服务器端,它只是更新数据库,然后将带有相关地址的人员发回给json对象,以便extjs可以更新前端。
问题是extjs只能更新人员网格而不能更新地址网格。 即使服务器确实响应了记录的更新版本(服务器给它一个id),新创建的地址记录仍然标记为脏。
有没有人遇到类似的东西,可以给我一些建议吗? 我意识到我没有提供很多代码,但我愿意分享更多代码,我只是不知道需要哪些代码。
修改 我使用MyStore.load()将数据加载到网格中 商店有一个如下配置的休息代理:
proxy:
{
type: 'rest',
url: 'persons', //general read url
headers : auth, //basic auth to connect to rest service
reader:
{
type: 'json',
root: 'persons',
successProperty: 'renderList'
},
writer:Ext.create('Ext.data.writer.DeepJson', {root: 'persons'}), //above writer class
api:
{
update: 'persons/person',
create: 'persons/person',
destroy: 'persons/person'
},
}