关于function中val值判空问题

本文分享了一位开发者在使用Datatables过程中遇到的一个关于如何正确判断单元格值为null的问题,通过调整判断条件成功解决了显示逻辑上的错误。

今天遇到获取datetables中获取row.name的值

传入单击事件中,判断这个值是否为空  最后发现是判断条件写错了

原条件

if(name == null || name == undefined || name == "" || name == "undefined"){
    $('.bb').css('display','block');
}else {
    alert("no");
    if (confirm("文件已存在是否覆盖?")){
        $('.bb').css('display','block');
    }else {

    }
}
改为:
if(name == null || name == undefined || name == "" || name == "undefined"|| name=="null"){
    $('.bb').css('display','block');
}else {
    alert("no");
    if (confirm("文件已存在是否覆盖?")){
        $('.bb').css('display','block');
    }else {

    }
}
就是少了一个“null”其实tatetables中获取的值是"null" 而不是null 按照惯性思维 我们都会直接写null
而且我在页面alert的时候获取到的值也是null所以这个问题困扰了我3.4个小时 后来页面dubug的时候时候发现是"null"
真是无话可说

@{ ViewBag.Title = "ProdResultsProdActualDetail"; Layout = "~/Views/Shared/_Layout.cshtml"; } @Html.AntiForgeryToken() <div class="x-body"> <div id="frmProdActualDetail" class="layui-form layui-form-pane"> <div class="layui-form-item"> <div class="layui-inline"> <label class="layui-form-label" style="width:130px;">产品序列号</label> <div class="layui-input-inline "> <input type="text" id="subLotId" name="subLotId" maxlength="50" autocomplete="off" class="layui-input rd" readonly> </div> </div> <div class="layui-inline"> <label class="layui-form-label" style="width:130px;">订单编号</label> <div class="layui-input-inline"> <input type="text" id="orderNo" name="orderNo" maxlength="25" autocomplete="off" class="layui-input rd" readonly> </div> </div> </div> <div class="layui-form-item"> <div class="layui-inline"> <label class="layui-form-label" style="width:130px;">产品名称</label> <div class="layui-input-inline "> <input type="text" id="productName" name="productName" maxlength="25" autocomplete="off" class="layui-input rd" readonly> </div> </div> <div class="layui-inline"> <label class="layui-form-label" style="width:130px;">产品图号</label> <div class="layui-input-inline"> <input type="text" id="productNo" name="productNo" maxlength="25" autocomplete="off" class="layui-input rd" readonly> </div> </div> </div> <div class="layui-form-item"> <div class="layui-inline"> <label class="layui-form-label" style="width:130px;">工艺路线编号</label> <div class="layui-input-inline "> <input type="text" id="processNo" name="processNo" maxlength="25" autocomplete="off" class="layui-input rd" readonly> </div> </div> <div class="layui-inline"> <label class="layui-form-label" style="width:130px;">工艺路线版本</label> <div class="layui-input-inline"> <input type="text" id="processVersion" name="processVersion" maxlength="10" autocomplete="off" class="layui-input rd" readonly> </div> </div> <div class="layui-inline"> <label class="layui-form-label">工程版本</label> <div class="layui-input-inline"> <input type="text" id="allotStepVersion" name="allotStepVersion" maxlength="10" autocomplete="off" class="layui-input rd" readonly> </div> </div> </div> <div> <div style="width:100%;"> 工序履历表 </div> <table class="layui-table" id="prodHistory" lay-filter="prodHistory"></table> </div> <div class="layui-row"> <div class="layui-col-sm6" style="padding-right:10px;"> 工步履历表 </div> <div class="layui-col-sm6" style="padding-left:10px;"> 步骤履历表 </div> </div> <div class="layui-row" style="height:280px;"> <div class="layui-col-sm6" style="padding-right:10px;margin-top:-6px;"> <table class="layui-table" id="workStepHistory" lay-filter="workStepHistory"></table> </div> <div class="layui-col-sm6" style="padding-left:10px;margin-top:-6px;"> <table class="layui-table" id="stepHistory" lay-filter="stepHistory"></table> </div> </div> <div class="layui-row"> <div class="layui-col-sm12"> @* 表单按钮--详情 *@ <script type="text/html" id="toolBarTpl"> <a lay-event="upload" class="layui-btn layui-btn-xs "><i class="layui-icon"></i>文件上传</a> </script> <table class="layui-table" id="dataTable" lay-filter="lfTable"></table> 动作履历表 </div> </div> <div class="layui-row" style="height:340px;"> <div class="layui-col-sm12" style="padding-right:10px;margin-top:-6px;"> <table class="layui-table" id="actionHistory" lay-filter="actionHistory"></table> </div> </div> </div> </div> <script> layui.use(['table', 'form','upload'], function () { var layer = layui.layer; var table = layui.table; var upload = layui.upload; var qrySubLotId = '@ViewBag.subLotId'; //工序履历表 table.render({ elem: '#prodHistory' , even: true , autoSort: false , page: false , height: 280 , cols: [[ { field: 'WORKBENCHCODE', title: '作业台编号', width: 120, }, { field: 'WORKBENCHNAME', title: '作业台名称', width: 130, }, { field: 'LOTNO', title: 'Lot号', width: 140 }, { field: 'PROCESSNUM', title: '工序号', width: 80 }, { field: 'PROCESSNAME', title: '工序名称', width: 120}, { field: 'PROCESSTEXTNO', title: '工序文本码', width: 130 }, { field: 'STARTTIME', title: '开始时间', width: 160, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'COMPLETETIME', title: '完成时间', width: 160, templet: function (d) { if (d.COMPLETETIME == "" || d.COMPLETETIME == null) return ""; return d.COMPLETETIME.replace('T', ' '); } }, { field: 'OPERSTARTSTATUS', title: '开工状态', width: 100, templet: function (d) { if (d.OPERSTARTSTATUS == 0) return "未申报"; else return "已申报"; } }, { field: 'OPERSTARTTIME', title: '开工时间', width: 160, templet: function (d) { if (d.OPERSTARTTIME == "" || d.OPERSTARTTIME == null || d.OPERSTARTTIME == "0001-01-01 00:00:00" || d.OPERSTARTTIME == "0001-01-01T00:00:00") return ""; return d.OPERSTARTTIME.replace('T', ' '); } }, { field: 'OPERENDSTATUS', title: '报工状态', width: 120, templet: function (d) { if (d.OPERENDSTATUS == 0) return "未申报"; else return "已申报"; } }, { field: 'OPERENDTIME', title: '报工时间', width: 160, templet: function (d) { if (d.OPERENDTIME == "" || d.OPERENDTIME == null || d.OPERENDTIME == "0001-01-01 00:00:00" || d.OPERENDTIME == "0001-01-01T00:00:00") return ""; return d.OPERENDTIME.replace('T', ' '); } }, { field: 'FORCEFLAG', title: '报工强制标识', width: 120, templet: function (d) { if (d.FORCEFLAG == 0) return ""; else return "强制报工"; } }, ]] , data: [] }); //工步履历表 table.render({ elem: '#workStepHistory' , even: true , autoSort: false , page: false , height: 280 , cols: [[ { field: 'PROCESSWORKNUM', title: '工步号', width: 80 }, { field: 'PROCESSWORKNAME', title: '工步名称', width: 120 }, { field: 'PROCESSWORKNO', title: '工步文本码', width: 130 }, { field: 'STARTTIME', title: '开始时间', width: 160, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'COMPLETETIME', title: '完成时间', width: 160, templet: function (d) { if (d.COMPLETETIME == "" || d.COMPLETETIME == null) return ""; return d.COMPLETETIME.replace('T', ' '); } }, ]], data:[] }); //步骤履历表 table.render({ elem: '#stepHistory' , even: true , autoSort: false , page: false , height: 280 , cols: [[ /* { field: 'LOTNO', title: 'Lot号', width: 120 },*/ { field: 'PROCESSWORKNUM', title: '工步号', width: 100 }, { field: 'STEPSEQ', title: '步骤号', width: 120 }, { field: 'STEPNAME', title: '步骤名称', width: 120 }, { field: 'STEPKIND_NAME', title: '步骤种类', width: 90 }, { field: 'STEPCUMULATIVE', title: '累计时间(秒)', width: 120 }, { field: 'STARTTIME', title: '开始时间', width: 160, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'COMPLETETIME', title: '完成时间', width: 160, templet: function (d) { if (d.COMPLETETIME == "" || d.COMPLETETIME == null) return ""; return d.COMPLETETIME.replace('T', ' '); } }, { field: 'USERCODE', title: '作业员编号', width: 120 }, { field: 'OPERSTARTSTATUS', title: '开工状态', width: 90, templet: function (d) { if (d.OPERSTARTSTATUS == 1) return "已申报"; else return ""; } }, { field: 'OPERSTARTTIME2', title: '开工时间', width: 150, templet: function (d) { if (d.OPERSTARTTIME == "" || d.OPERSTARTTIME == null) return ""; return d.OPERSTARTTIME.replace('T', ' '); }}, { field: 'OPERENDSTATUS', title: '报工状态', width: 120, templet: function (d) { if (d.OPERENDSTATUS == 1) return "已申报"; else return ""; } }, { field: 'OPERENDTIME2', title: '报工时间', width: 150, templet: function (d) { if (d.OPERENDTIME == "" || d.OPERENDTIME == null) return ""; return d.OPERENDTIME.replace('T', ' '); } }, { fixed: 'right', title: '操作', width: 90, align: 'center', toolbar: '#toolBarTpl' }, ]], }); function statusName(d){ if (d == "0") { return "未开始"; } else if (d == "1") { return "OK"; } else if (d == "2") { return "跳步"; } else if (d == "3") { return "暂停"; } else if (d == "4") { return "进行中"; } else if (d == "5") { return "停止"; } else if (d == "6") { return "返工"; } else if (d == "7") { return "手动完成"; } else if (d == "8") { return "请求暂停"; } else if (d == "9") { return "NG"; } else if (d == "10") { return "废弃"; } else { return "未知"; } } //加载步骤动作履历 function loadActionHistory(stepKind, d) { let column = []; //取料 if (stepKind == "0") { column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'ACTIONSTSNAME', title: '动作状态', width: 120, templet: function (d) { return statusName(d.ACTIONSTS); } }, { field: 'STARTTIME', title: '作业时间', width: 200, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'ACTIONVALUE10', title: '物料盒号', width: 120 }, { field: 'ACTIONVALUE11', title: '物料编号', width: 200 }, { field: 'ACTIONVALUE2', title: '取料量', width: 110 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; } //工具 if (stepKind == "1") { column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'ACTIONSTSName', title: '动作状态', width: 110, templet: function (d) { return statusName(d.ACTIONSTS); } }, { field: 'ACTIONVALUE10', title: '螺丝钉编号', width: 100 }, { field: 'STARTTIME', title: '作业时间', width: 200, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'ACTIONVALUE1', title: '理论扭矩最大', width: 140 }, { field: 'ACTIONVALUE2', title: '理论扭矩最小', width: 140 }, { field: 'ACTIONVALUE3', title: '实际扭矩', width: 110 }, { field: 'ACTIONVALUE4', title: '理论角度最大', width: 140 }, { field: 'ACTIONVALUE5', title: '理论角度最小', width: 140 }, { field: 'ACTIONVALUE6', title: '实际角度', width: 110 }, { field: 'ACTIONVALUE7', title: '理论时间最大', width: 140 }, { field: 'ACTIONVALUE8', title: '理论时间最小', width: 140 }, { field: 'ACTIONVALUE9', title: '实际时间', width: 110 }, { field: 'ACTIONVALUE11', title: '程序号', width: 90 }, { field: 'ACTIONVALUE49', title: '制造商序列号', width: 140 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; } //拍照 if (stepKind == "3") { column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'ACTIONSTSName', title: '动作状态', width: 120, templet: function (d) { return statusName(d.ACTIONSTS); } }, { field: 'STARTTIME', title: '作业时间', width: 200, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'ACTIONVALUE7', title: '照片文件名', width: 120 }, { field: 'ACTIONVALUE8', title: 'FTP路径', width: 200 }, { field: 'ACTIONVALUE10', title: '视觉检测位置号', width: 160 }, { field: 'ACTIONVALUE14', title: '视觉检测结果', width: 150 }, { field: 'ACTIONVALUE15', title: '是否复结果', width: 150 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; } //条码采集 if (stepKind == "5") { column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'ACTIONSTSName', title: '动作状态', width: 120, templet: function (d) { return statusName(d.ACTIONSTS); } }, { field: 'ACTIONVALUE10', title: '采集顺序', width: 120 }, { field: 'STARTTIME', title: '作业时间', width: 200, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'ACTIONVALUE11', title: '物料编号', width: 200 }, { field: 'ACTIONVALUE5', title: '实际采集内容', width: 200 }, { field: 'ACTIONVALUE4', title: '截取后条码号', width: 200 }, { field: 'ACTIONVALUE3', title: '关键件位置号', width: 200 }, { field: 'ACTIONVALUE2', title: '定结果', width: 200 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; } //检查项 if (stepKind == "7") { column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'ACTIONSTSName', title: '动作状态', width: 120, templet: function (d) { return statusName(d.ACTIONSTS); } }, { field: 'STARTTIME', title: '作业时间', width: 200, templet: function (d) { if (d.STARTTIME == "" || d.STARTTIME == null) return ""; return d.STARTTIME.replace('T', ' '); } }, { field: 'ACTIONVALUE6', title: '检查项结果', width: 400 }, { field: 'ACTIONVALUE7', title: '检查项内容', width: 400 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; } //检测项 if (stepKind == "8") { if(d.length==0 || d[0].HANDEQUIPMENT!=1){ column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'HANDEQUIPMENT_NAME', title: '测试设备区分', width: 120, templet: function (d) { if (d.HANDEQUIPMENT == 1) { return "手动设备"; } else { return "自动设备"; } } }, { field: 'STARTTIME', title: '开始时间', width: 200, templet: function (d) { if (d.START_TIME == "" || d.START_TIME == null) return ""; return d.START_TIME.replace('T', ' '); } }, { field: 'ENDTIME', title: '结束时间', width: 200, templet: function (d) { if (d.END_TIME == "" || d.END_TIME == null) return ""; return d.END_TIME.replace('T', ' '); } }, { field: 'TEST_SEQ', title: '顺序号', width: 90 }, { field: 'PARENT_ITEM', title: '测试父项名称', width: 130 }, { field: 'SUB_ITEM', title: '测试子项名称', width: 120 }, { field: 'STEP', title: '测试项名', width: 110 }, { field: 'RESULT', title: '测试结果(子项)', width: 140 }, { field: 'VALUE_UNIT', title: '测试单位', width: 120 }, { field: 'VALUE_UNIT_EN', title: '测试单位2', width: 120 }, { field: 'UPPER_LIMIT', title: '测试上限', width: 120 }, { field: 'LOWER_LIMIT', title: '测试下限', width: 120 }, { field: 'RESULT_BOOLE', title: '布尔量测试结果', width: 140 }, { field: 'RESULT_NUMBERIC', title: '数测试结果', width: 120 }, { field: 'RESULT_STRING', title: '字符串测试结果', width: 140 }, { field: 'PRINT_FLAG', title: '打印标识位', width: 110 }, { field: 'TOOLMNGNO', title: '工具管理编号', width: 130 }, { field: 'TOOLMATNAME', title: '工具名称', width: 130 }, { field: 'MEASUR_PERIOD', title: '校验周期', width: 100 }, { field: 'LAST_MEASUR_TIME', title: '校验时间', width: 120 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; }else{ column = [ { field: 'STEPSEQ', title: '步骤号', width: 110 }, { field: 'HANDEQUIPMENT_NAME', title: '测试设备区分', width: 120, templet: function (d) { if (d.HANDEQUIPMENT == 1) { return "手动设备"; } else { return "自动设备"; } } }, { field: 'STARTTIME', title: '开始时间', width: 200, templet: function (d) { if (d.START_TIME == "" || d.START_TIME == null) return ""; return d.START_TIME.replace('T', ' '); } }, { field: 'ENDTIME', title: '结束时间', width: 200, templet: function (d) { if (d.END_TIME == "" || d.END_TIME == null) return ""; return d.END_TIME.replace('T', ' '); } }, { field: 'TEST_SEQ', title: '顺序号', width: 90 }, { field: 'PARENT_ITEM', title: '检测项目名称', width: 130 }, { field: 'SUB_ITEM', title: '检测项目代号', width: 120 }, { field: 'STEP', title: '检测项目公式', width: 120 }, { field: 'RESULT', title: '测试结果(子项)', width: 140 }, { field: 'VALUE_UNIT', title: '测试单位', width: 120 }, { field: 'VALUE_UNIT_EN', title: '测试单位2', width: 120 }, { field: 'UPPER_LIMIT', title: '测试上限', width: 120 }, { field: 'LOWER_LIMIT', title: '测试下限', width: 120 }, { field: 'RESULT_BOOLE', title: '布尔量测试结果', width: 140 }, { field: 'RESULT_NUMBERIC', title: '数测试结果', width: 120 }, { field: 'RESULT_STRING', title: '字符串测试结果', width: 140 }, { field: 'PRINT_FLAG_NAME', title: '打印标识位', width: 110,templete:function(d){ if(d.PRINT_FLAG==1){ return "报表打印"; }else{ return ""; } } }, { field: 'TOOLMNGNO', title: '工具管理编号', width: 130 }, { field: 'TOOLMATNAME', title: '工具名称', width: 130 }, { field: 'MEASUR_PERIOD', title: '校验周期', width: 100 }, { field: 'LAST_MEASUR_TIME', title: '校验时间', width: 120 }, { field: 'USERCODE', title: '作业员编号', width: 160 }, ]; } } //动作履历表 table.render({ elem: '#actionHistory' , even: true , autoSort: false , page: true , height: 300 , cols: [column], data: d }); } //loadActionHistory("1", []); //产品履历信息获取 function initCallBackProdInfoInit(data) { closeLoading(); if (data.success == false) { alertMessage(data.message); return; } let ProdInfo = JSON.parse(data.initData); if (ProdInfo.length > 0) { $("#orderNo").val(ProdInfo[0].ORDERNO); $("#subLotId").val(ProdInfo[0].SUBLOTID); $("#processNo").val(ProdInfo[0].PROCESSNO); $("#processVersion").val(ProdInfo[0].PROCESSVERSION); $("#productNo").val(ProdInfo[0].PRODUCTNO); $("#productName").val(ProdInfo[0].PRODUCTNAME); $("#allotStepVersion").val(ProdInfo[0].ALLOTSTEPVERSION); } let pd = JSON.parse(data.procNumLst); table.reload("prodHistory", { limit: pd.length, data: pd }); } ajaxRequest({ SubLotId: qrySubLotId }, '../prodresults/ProdActualDetailInit', initCallBackProdInfoInit); //工步行信息获取 function initCallBackWorkStepHistory(data) { closeLoading(); if (data.success == false) { alertMessage(data.message); return; } let d = JSON.parse(data.data); table.reload("workStepHistory", { limit: d.length, data: d }); table.reload("stepHistory", { limit: 0, data: [] }); } table.on('row(prodHistory)', function (obj) { loading(); //obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click"); //标注选中样式 obj.tr.addClass('clickRow').siblings().removeClass('clickRow'); var data = obj.data; ajaxRequest({ processNum: data.PROCESSNUM, lotNo: data.LOTNO, subLotId: data.SUBLOTID, operHistoryNo: data.OPERHISTORYNO }, '../prodresults/FindWorkStepHistory', initCallBackWorkStepHistory); }); //步骤行信息获取 function initCallBackStepHistory(data) { closeLoading(); if (data.success == false) { alertMessage(data.message); return; } let d = JSON.parse(data.data); table.reload("stepHistory", { limit: d.length, data: d }); } table.on('row(workStepHistory)', function (obj) { loading(); //obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click"); obj.tr.addClass('clickRow').siblings().removeClass('clickRow'); var data = obj.data; ajaxRequest({ processNum: data.PROCESSNUM, processWorkNum: data.PROCESSWORKNUM, lotNo: data.LOTNO, subLotId: data.SUBLOTID, operHistoryNo: data.OPERHISTORYNO }, '../prodresults/FindStepHistory', initCallBackStepHistory); }); table.on('row(stepHistory)', function (obj) { loading(); obj.tr.addClass('clickRow').siblings().removeClass('clickRow'); let data = obj.data; closeLoading(); ajaxRequest({ sublotId: data.SUBLOTID, factStepId: data.FACTSTEPID, lotNo: data.LOTNO, stepKind: data.STEPKIND }, '../ProdResults/FindStepActionHistory', d => { closeLoading(); if (d.success == true) { //loadActionHistory(data.STEPKIND, d.data); loadActionHistory(data.STEPKIND, d.data); } else { //loadActionHistory(data.STEPKIND, []); loadActionHistory(data.STEPKIND, []); alertMessage(d.message); } }); }); // 监听工具条操作 table.on('tool(lfTable)', function (obj) { var data = obj.data; if (obj.event === 'upload') { document.getElementById('fileInput').click(); // 触发文件选择 } }); function uploadManualInfoFile(uploadPath) { var headers1 = { "__RequestVerificationToken": $("input[name=__RequestVerificationToken]").val(), "Authorization": getAuthToken() }; layui.upload.render({ elem: '#fileInput', url: uploadPath, auto: true, accept: 'file', size: 200 * 1024 * 1024, exts: '*', headers: headers1, choose: function (obj) { }, before: function () { layer.load(2); // 显示加载中 }, done: function (res) { layer.closeAll('loading'); if (res.success) { layer.msg('上传成功'); } else { layer.msg(res.message || '上传失败'); } }, error: function () { layer.closeAll('loading'); layer.msg('上传出错'); } }); } //上传手顺信息文件 uploadManualInfoFile( "tabData", '../ProdActualDetail/UploadManualInfo', "*/*", "file", "*"); }) </script>是否有错误
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值