今天在调试的时候发现有个重复数据问题,如下,可以重复输入,
又不想去后台跑webservice,直接在JS端取得所有的表格对应字段内容,利用for循环,然后每行对比,发现有重复数据后,
直接把originaValue返回给它,不修改,后return出来,这样就可以避免重复输入。
1 listeners: { 2 afteredit: function (e) { 3 4 if (e.field == 'ApplyStaffno') { 5 var record = this.getStore().getRange(); 6 var i = 0; 7 for (i = 0; i < record.length; i++) { 8 if (e.row != i) { //修改的当前行不进行比对 9 if (record[i].get('ApplyStaffno') == e.value) { 10 record[e.row].set('ApplyStaffno', e.originalValue); 11 this.getStore().commitChanges(); 12 return; 13 } else { 14 15 } 16 } 17 } 18 Ext.Msg.wait('Waiting', 'Waiting'); 19 TAAjax.request({ 20 url: 'csr/basefun.ashx', 21 params: { action: 'getNameAndSection', StaffNo: e.value }, 22 success: function (req, ops) { 23 Ext.Msg.hide(); 24 var data = Ext.decode(req.responseText); 25 if (Ext.isEmpty(data.name) || Ext.isEmpty(data.section)) { 26 e.record.set('HoursOfTheYear', ''); 27 e.record.set('ApplyStaffname', ''); 28 e.record.set('ApplystaffDept', ''); 29 return; 30 } 31 else { 32 var arrSection = this.mainPanel.getSection(); 33 var bln = this.mainPanel.isChargehand(); 34 var staffno = this.mainPanel.getChargeman(); 35 var rlt = arrSection.indexOf(data.section); 36 if (rlt != -1) { 37 e.record.set('ApplyStaffname', data.name); 38 e.record.set('ApplystaffDept', data.section); 39 } else { 40 if (bln && e.value == staffno) { 41 e.record.set('ApplyStaffname', data.name); 42 e.record.set('ApplystaffDept', data.section); 43 } else { 44 Ext.Msg.alert('提示', GetErrDescr('?CSRE011')); 45 e.record.set('ApplyStaffno', ''); 46 return; 47 } 48 } 49 } 50 Ext.Msg.wait('Waiting', 'Waiting'); 51 TAAjax.request({ 52 url: 'csr/csr005.ashx', 53 params: { action: 'getTheYearJoinCount', StaffNo: e.value }, 54 success: function (req, ops) { 55 Ext.Msg.hide(); 56 var data = req.responseText; 57 e.record.set('HoursOfTheYear', data); 58 this.resetFM(e.record); 59 }, 60 failure: function () { 61 Ext.Msg.hide(); 62 }, 63 scope: this 64 }); 65 }, 66 failure: function () { 67 Ext.Msg.hide(); 68 }, 69 scope: this 70 }); 71 }, 72 scope: this 73 }