@nonino
我想我知道该怎么做,但我也有类似的问题。我实际上无法让我的协会给我相关的数据。反正从我凑在互联网上创建一个自定义的作家这样或只是在默认作家getRecordData:功能(记录操作)
,这里是我的自定义作家
Ext.define('Wakanda.writer', {
extend: 'Ext.data.writer.Json',
// alternateClassName: 'SimplyFundraising.data.WakandaWriter',
alias: 'writer.wakanda',
writeAllFields: false,
getRecordData: function(record,operation) {
debugger;
Ext.apply(record.data,record.getAssociatedData());
debugger;
var isPhantom = record.phantom === true,
writeAll = this.writeAllFields || isPhantom,
nameProperty = this.nameProperty,
fields = record.fields,
data = {},
changes,
name,
field,
key;
if (writeAll) {
// console.log("getRecordData1", this, arguments);
fields.each(function(field){
if (field.persist) {
debugger;
name = field[nameProperty] || field.name;
data[name] = record.get(field.name);
} else {
}
});
} else {
changes = record.getChanges();
debugger;
// console.log("getRecordData2", this, arguments, changes);
for (key in changes) {
if (changes.hasOwnProperty(key)) {
field = fields.get(key);
name = field[nameProperty] || field.name;
data[name] = changes[key];
}
}
if (!isPhantom) {
debugger;
data[record.idProperty] = record.getId();
if(operation.action !== 'destroy'){
data[record.stampProperty] = record.get(record.stampProperty);
}
}
}
return {'__ENTITIES': [data]};
}
});
我觉得最关键的是在getRecordData中我有一个语句Ext.apply(record.data,record.getAssociatedData());如果record.getAssociatedData确实返回数据,那么Ext.apply语句会将您当前的record.data与record.getAssociatedData合并为一个json文件。至少这是我希望发生的事情。直到我正确设置了关联后才能测试。
希望这有助于 丹
getRecordData: function(record,operation) {
debugger;
Ext.apply(record.data,record.getAssociatedData());
debugger;
来源
2013-05-13 17:51:27
dan