2016-03-07 41 views
0

我不能明白,我的代碼在哪裏worng?我已經實現了handsontable,一切工作都很好,期望驗證,在驗證過程中它會迭代多次。但癢25次handontable驗證部分不工作,它迭代26,其中相同的代碼在其他頁面工作

大家好,我不能明白,我的代碼worng?我已經實現了handsontable,一切工作都很好,期望驗證,在驗證過程中它會迭代多次。但是25次加熱

enter code here 
    $(document).ready(function() { 
    $('#btnValidateSave').on('click',function() { 
    debugger; 
    $('#HSTable').handsontable('validateCells', function (isPass) { 
     if (isPass) { 
      SaveData(); 
      alert("Saving data"); 
     } 
     else { 
      alert("Please enter the data in correctformat"); 
     } 
    }); 
    //$('#HSTable').handsontable('render'); 
    }); 

    $('#btnUpload').click(function() { 
    upload(); 

      }) 

     }); 


     function upload() 
      { 
var formData = new FormData(); 
var totalFiles = document.getElementById("UploadFile").files.length; 
for (var i = 0; i < totalFiles; i++) { 
    var file = document.getElementById("UploadFile").files[i]; 
     formData.append("Document", file); 
    } 
    $.ajax({ 
     url: "/BulkUpload/UploadFile", 
     type: "POST", 
     dataType: "JSON", 
     data: formData, 
     contentType: false, 
     processData: false, 
     success: function (result) { 
      if (result != null) { 
       DataBind(result); 
      } 
      else 
      { 

      } 
     } 
     }); 
     } 


     function DataBind(result) { 

    $("#HSTable").handsontable({ 
    data: result, 
    startRows: 100, 
    rowHeaders: true, 
    colHeaders: ["Agent","Invoice No", "Issue Date", "Passanger", 
     "Empno", "ProjectCode", "RequestNo", "RequireDate", 
     "AirlineName", "AirLineCode", "Ticket", "Locator", "FlightNO",   "DetpDate", 
     "ReturnDate", "ServiceClass", "ServiceType", "TravelType", "TripType", "Sector", 
     "OrgnDtn", "Region", "BaseFare", "TotalTax", "ServiceFare", "TotalFare", "Remarks"], 
    columns: [ 
     {data: 'Agent'}, 
     { data:'InvoiceNo' }, 
     { data: 'IssueDate' }, 
     { 
      data: 'Passenger', 

     }, 
     { 
      data: 'EmpNo', 

     }, 
     { 
      data: 'ProjectCode', 

     }, 
     { 
      data: 'RequestNo', 

     }, 
     { data:'RequireDate'}, 
     {data:'AirLineName'}, 
     { data: 'AirLinecode' }, 
     { data: 'TicketNo' }, 
     { data: 'Locator' }, 
     { data: 'FlightNo' }, 
     { date: 'DepDate' }, 
     { date: 'ReturnDate' }, 
    { data: 'ServiceClass' }, 
    { data: 'ServiceType' }, 
    { data: 'TravelType' }, 
    { data: 'tripType' }, 
    { data: 'Sector'}, 
    { data: 'OrgDtn' }, 
    { data: 'Region' }, 
    { data: 'BaseFare' }, 
    { data: 'TotalTax' }, 
    { data: 'ServiceFee' }, 
    { data: 'TotalFare' }, 
    { data: 'Remarks' } 

    ], 
    colWidths: 85, 
     }); 

     } 
     var notEmpty=function(value, callback) { 
    if (!value || String(value).length === 0) { 
     callback(false); 

     } 
      else { 
    callback(true); 
} 

};

 var EmailValidator = function (value, callback) { 
    if (/[email protected]@.+/.test(value)) { 
    callback(true); 
} 
else { 
    callback(false); 
} 

      }; 


    function SaveData() { 

var data = [{}]; 
var $container = document.getElementById('#HSTable'); 
var colHeaderList = $('#HSTable').handsontable("getColHeader"); 
var rowHeaderList = $('#HSTable').handsontable("getRowHeader"); 
var tableData = $('#HSTable').handsontable("getData"); 
var obj = $('#HSTable').handsontable("getData"); 

var ObjBulk = []; 
debugger; 
//for (var i = 0; i < obj.length; i++) { 
for(var i=0;i<obj.length;i++){ 
     var user = new Object(); 

    user.Agent = obj[i]["0"]; 
    user.InvoiceNo = obj[i]["1"];  
    user.IssueDate = obj[i]["2"]; 
    user.Passenger = obj[i]["3"]; 
    user.EmpNo = obj[i]["4"]; 
    user.ProjectCode = obj[i]["5"]; 
    user.RequestNo = obj[i]["6"]; 
    user.RequireDate = obj[i]["7"]; 
    user.AirLineName = obj[i]["8"]; 
    user.AirLineCode = obj[i]["9"]; 
    user.TicketNo = obj[i]["10"]; 
    user.Locator = obj[i]["11"]; 
    user.FlightNo = obj[i]["12"]; 
    user.DeptDate = obj[i]["13"]; 
    user.ReturnDate = obj[i]["14"]; 
    user.ServiceClass = obj[i]["15"]; 
    user.ServiceType = obj[i]["16"]; 
    user.TravelType = obj[i]["17"]; 
    user.Sector = obj[i]["18"]; 
    user.OrgDtn = obj[i]["19"]; 
    user.Region = obj[i]["20"]; 
    user.BaseFare = obj[i]["21"]; 
    user.TotalTax = obj[i]["22"]; 
    user.ServiceFee = obj[i]["23"]; 
    user.TotalTax = obj[i]["24"]; 
    user.ServiceFee = obj[i]["25"]; 
    user.TotalFare = obj[i]["26"]; 
    user.Remarks = obj[i]["27"]; 
    ObjBulk.push(user); 
    } 
//}; 

     $.ajax({ 
    url: "/BulkUpload/SaveBulkData", 
    type: "POST", 
    contentType: "application/json", 
    dataType: "JSON", 
    data: JSON.stringify(ObjBulk), 
    success: function (data) { 
     alert(data); 
    }, 
    error: function (xhr) { 
     alert(xhr) 
    } 

     }); 

    }; 

回答

0

將emailValidator函數應用於包含電子郵件ID的列。

爲如:

columns: [ 
     {data: 'id', type: 'numeric'}, 
     {data: 'name.first'}, 
     {data: 'name.last'}, 
     {data: 'ip', validator: ipValidatorRegexp, allowInvalid: true}, 
     {data: 'email', validator: emailValidator, allowInvalid: false} 
    ] 

你可以參考fiddle for demo

+0

我不使用郵件驗證場,我用了四個柱NotEmpty驗證。在按鈕單擊事件我打電話驗證功能,它正在工作但它是迭代26次,假設如果我給予警報windown驗證真正26時間警報窗口即將到來。 –

+0

好的!您已在整個手錶中應用驗證,因此它遍歷每個單元格。您只需要對該特定列應用驗證。 – Mazzu

+0

使用afterValidate回調,它將在驗證後每行調用一次。 – Mazzu

相關問題