【发布时间】:2015-07-02 08:35:46
【问题描述】:
我目前正在处理使用 RowEditing 插件的网格,当我单击链接到网格的“添加”按钮时,一条新的空记录将添加到网格绑定到的存储中。当我添加一个新行时,我可以检查用户尝试添加的值,如果这个 'user_id' 值为空或重复,我会提醒用户他的重复条目并将其从商店中删除。
我有一个我无法弄清楚的边缘情况 - 当用户想要更新现有行并将“user_id”更改为现有行或空行时,就会发生这种情况。我不想擦除这条记录,我只想假设用户犯了一个错误而不更新这条记录,我想撤消他/她的更新。
这是我店铺的更新方法:
update : function(com, record, successful, eOpts){
var store = Ext.data.StoreManager.lookup('EpaymentKioskOptStores');
var table_id = record.data.kiosk_user_id;
var _try = false;
var _wipe = false;
//if the record is empty handle it
if(table_id.trim() == null || table_id.trim() == undefined || table_id.trim() == ''){
if(record.dirty){
//restore to original value, and cancel update
record.data.kiosk_user_id = record.modified.kiosk_user_id;
_try = true;
}else{
store.remove(record);
_wipe = true;
}
}
//if the record's kiosk_user_id is not empty
else{
store.each(function(r){
var temp = r.data.kiosk_user_id;
//the record we are trying to enter is a new record
if(record.phantom){
//make sure the record is new and if we find another with the same key we can wipe record
if(!r.phantom && (temp == table_id)){
store.remove(record);
_wipe = true;
}
}
else{
//somehow have to make sure the record and r arent the same
if((r.internalId != record.internalId) && (temp == table_id)){
record.data.kiosk_user_id = record.modified.kiosk_user_id;
_try = true;
}
}
});
}
if(_try){
Ext.Msg.alert('Warning', 'Your change was reverted');
store.commitChanges();
}
if(_wipe){
Ext.Msg.alert('Alert', 'Your changes were discarded');
store.commitChanges();
}
}
编辑:这是我为解决我的问题而实施的修复程序,它有点 hacky
【问题讨论】: