对于 ux/form/ItemSelector.js 文件 中的setValue() 函数:
4.1版本的问题:
当将左边所有选项添加到右边时,用getValue()取值时取不到最后一项。
4.2版本中的为:
setValue: function(value) {
var me = this,
fromField = me.fromField,
toField = me.toField,
fromStore = fromField.store,
toStore = toField.store,
selected;
// Wait for from store to be loaded
if (!me.fromStorePopulated) {
me.fromField.store.on({
load: Ext.Function.bind(me.setValue, me, [value]),
single: true
});
return;
}
value = me.setupValue(value);
me.mixins.field.setValue.call(me, value);
selected = me.getRecordsForValue(value);
// Clear both left and right Stores.
// Both stores must not fire events during this process.
fromStore.suspendEvents();
toStore.suspendEvents();
fromStore.removeAll();
toStore.removeAll();
// Reset fromStore
me.populateFromStore(me.store);
// Copy selection across to toStore
Ext.Array.forEach(selected, function(rec){
// In the from store, move it over
if (fromStore.indexOf(rec) > -1) {
fromStore.remove(rec);
}
toStore.add(rec);
});
// Stores may now fire events
fromStore.resumeEvents();
toStore.resumeEvents();
// Refresh both sides and then update the app layout
Ext.suspendLayouts();
fromField.boundList.refresh();
toField.boundList.refresh();
Ext.resumeLayouts(true);
},
4.2版本中的为(注:4.2版本有些也是上面代码):
setValue: function(value){
var me = this,
fromStore = me.fromField.store,
toStore = me.toField.store,
selected;
// Wait for from store to be loaded
if (!me.fromField.store.getCount()) {
me.fromField.store.on({
load: Ext.Function.bind(me.setValue, me, [value]),
single: true
});
return;
}
value = me.setupValue(value);
me.mixins.field.setValue.call(me, value);
selected = me.getRecordsForValue(value);
Ext.Array.forEach(toStore.getRange(), function(rec){
if (!Ext.Array.contains(selected, rec)) {
// not in the selected group, remove it from the toStore
toStore.remove(rec);
fromStore.add(rec);
}
});
toStore.removeAll();
Ext.Array.forEach(selected, function(rec){
// In the from store, move it over
if (fromStore.indexOf(rec) > -1) {
fromStore.remove(rec);
}
toStore.add(rec);
});
},