您可以通过应用以下覆盖来使您的行选择在商店重新加载后仍然存在:
Ext.override(Ext.view.View, {
preserveSelectionOnRefresh: true,
constructor: function() {
this.callOverridden(arguments);
if (this.preserveSelectionOnRefresh) {
this.mon(this.getStore(), {
beforeload: this.beforeStoreLoadPreserveSelectionRoutine,
scope: this
});
}
},
beforeStoreLoadPreserveSelectionRoutine: function() {
var sm = this.getSelectionModel(),
selection = sm.getSelection(),
i = 0,
l = selection.length,
savedSelection = [];
delete sm.savedSelection;
for (; i < l; i++) {
savedSelection.push(selection[i].getId());
}
if (savedSelection.length) {
sm.savedSelection = savedSelection;
}
}
});
Ext.override(Ext.selection.Model, {
refresh: function() {
// include selections saved across store reloads
if (this.savedSelection && this.savedSelection.length) {
var rs = [],
r,
j = 0,
l = this.savedSelection.length;
for (; j < l; j++) {
r = this.store.getById(this.savedSelection[j]);
if (r) {
rs.push(r);
}
}
if (rs.length) {
this.select(rs, false, true);
}
}
this.callOverridden();
delete this.savedSelection;
}
});
他们所做的只是在重新加载商店之前保存选择的内容,并确保在刷新视图后再次选择这些记录。在 Ext JS 4.1.2 上测试。