-1

这是我在 jquery 中的表:-

var tbody = $('#tblCsvRecords tbody'),
props = ["ShipmentType", "SCAC", "ShipmentControlNumber", "ProvinceofLoading", 
"ShipperName", "ConsigneeName"];
$.each(filedata, function (key, value) {
var tr = $('<tr>');
$.each(props, function (key, prop) {
$('<td>').html(value[prop]).appendTo(tr);
});
tbody.append(tr);
});

这是 jquery 中的验证-

$.each(globalfiledata, function (key, value) {
if (value.ShipmentType != ("Regular Bill" || "Section 321")) {
           //show error sign and view error link as shown in image
}
}); 

html 表 -

<div id="tablediv" class="table-responsive">                                           
<table id="tblCsvRecords" class="table table3-1 bg-white no-margin-bottom">
<thead>
<tr>
<th>Shipment Type </th>
<th>SCAC </th>
<th>Shipment Control Number </th>
<th>Port of Loading </th>
<th>Shipper Name </th>
<th>Consignee Name </th>
<th>Validated </th>
</tr>
</thead>
<tbody>
</tbody>
</table id>
</div>

我想在表的已验证列中显示弹出窗口的错误符号和查看错误链接。我怎样才能做到这一点? 表格的已验证列的图像

如果 Iserror 为真,我想在模式中显示错误消息 -“输入有效的货件类型”我应该怎么做?以下是工作更新的代码-

4

1 回答 1

0

因此,您无需重复globalfiledata验证。您可以在构建表格时进行验证,这里:

$.each(filedata, function (key, value) {
    var tr = $('<tr>');
    var isError = false; //set isError false at the beginning of every row iteration
    $.each(props, function (key, prop) {
         //do your validation here
         if(prop === "ShipmentType" && value !== ("Regular Bill" || "Section 321")) {
            isError = true;
        }
        $('<td>').text(value).appendTo(tr); //fixed this line in your code to match your data structure, and to actually write the value to the td text because it's not html
    });
    //then, the last column is for Validation, so add your validation td here:
    var td = $('<td>');
    if(isError) {
        //insert your error image and link here, which will look something like:
        td.text('View Error');
        var link = $('<a>').attr('href','//href value goes here');
        $('<img>').attr('src','///img src goes here').wrap(link).appendTo(td);
    }
    td.appendTo(tr);
    tbody.append(tr);
});
于 2020-12-29T20:38:20.450 回答