これは興味深いことですが、私はこの簡単な問題を解決してExtについて多くのことを学びました。
私が見つけた解決策は、BatchVisitorクラスをオーバーライドして、SessionクラスのprivateメソッドvisitDataから生成されたイベントonCleanRecordのイベントハンドラを使用することです。
各レコードについて、マトリックスの左側のエンティティを探し、変更があれば、BatchVisitorオリジナルクラスで定義されているonDirtyRecordのハンドラを呼び出します。
コード:それは私のニーズのために非常によく動作し
Ext.define('Ext.overrides.data.session.BatchVisitor', {
override: 'Ext.data.session.BatchVisitor',
onCleanRecord: function (record) {
var matrices = record.session.matrices
bucket = null,
ops = [],
recordId = record.id,
className = record.$className;
// Before anything I check that the record does not exists in the bucket
// If it exists then any change on matrices will be considered (so leave)
try {
bucket = this.map[record.$className];
ops.concat(bucket.create || [], bucket.destroy || [], bucket.update || []);
var found = ops.findIndex(function (element, index, array) {
if (element.id === recordId) {
return true;
}
});
if (found != -1) {
return;
}
}
catch (e) {
// Do nothing
}
// Now I look for changes on matrices
for (name in matrices) {
matrix = matrices[name].left;
if (className === matrix.role.cls.$className) {
slices = matrix.slices;
for (id in slices) {
slice = slices[id];
members = slice.members;
for (id2 in members) {
id1 = members[id2][0]; // This is left side id, right side is index 1
state = members[id2][2];
if (id1 !== recordId) { // Not left side => leave
break;
}
if (state) { // Association changed
this.onDirtyRecord(record);
// Same case as above now it exists in the bucket (so leave)
return;
}
}
}
}
}
}
});
、おそらくそれは文句を言わない他の人のために最善の解決策になるが、とにかく出発点となることができます。
最後に、まだ明確でない場合は、メソッドgetSaveBatchにリレーションシップの変更を検出する機能があります。