前台显示undefined

后台传过来一个集合,其中有的值为null,前台却显示undefined。调试后发现ajax自动的把为空的字段设成了undefined。

//搜索参数
var param = "";
//分页查询数据
var pagers = function(currentPage,pageSize) {
    $.ajax({
        url:"../api/getBcRebateDanhao"+param,
        data:{"currentPage":currentPage,"pageSize":pageSize,"userCode":userCode},
        type:"POST",
        dataType:"json",
        success: function(data){
            if(""==data.result){
                return false;
            }
            $("#MyTable").children("tbody").html("");
            $.each(data.result.records,function(index,item){
                var gmtCreate = "";
                if(item.gmtCreate != "" && item.gmtCreate != null) {
                    gmtCreate = formatDateNew(item.gmtCreate, "/");
                }
                var failureTime = "";
                if(item.failureTime != "" && item.failureTime != null) {
                    failureTime = formatDateNew(item.failureTime, "/");
                }
                var ck = '';
                if(item.cashFlag=='2')
                    ck = "disabled='disabled'";
                else if(item.cashFlag=='3')
                    ck = "disabled='disabled'";
                else if(item.cashFlag=='4')
                    ck = "disabled='disabled'";

                var s = '';
                if(item.cashFlag=='0')
                    s = '待公议';
                else if(item.cashFlag=='1')
                    s = '保存';
                else if(item.cashFlag=='2')
                    s = '待公议';
                else if(item.cashFlag=='3')
                    s = '公议中';
                else if(item.cashFlag=='4')
                    s = '公议通过';
                else if(item.cashFlag=='5')
                    s = '驳回';
                var t = '';
                if(item.deletedFlag=='0')
                    t = '有效';
                else if(item.deletedFlag=='1')
                    t = '失效';

                $("#MyTable").children("tbody").append("<tr><td style='font-size:11px;' class='my_td'><input type='checkbox' "+status+" onclick='check(this)' id='ck"+index+"' name='ck' value='"+item.id+"'></td><td style='font-size:11px;' >"+item.bak2+"</td><td class='my_td'><input type='hidden' id='id"+index+"' value='"+item.id+"' /><button onclick='editCkeckList("+index+")' title='修改' name='updateButton' class='btn btn-xs btn-default'><i class='fa fa fa-pencil'></i></button></td><td class='my_td'>"+s+"</td><td class='my_td'>"+gmtCreate+"</td><td class='my_td'>"+item.moduleNumber+"</td><td style='font-size:11px;' class='my_td'>"+(item.vendorDesc==undefined?"":item.vendorDesc)+"</td><td class='my_td'>"+(item.danhao==undefined?"":item.danhao)+"</td><td class='my_td'>"+(item.operatorName==undefined?"":item.operatorName)+"</td><td class='my_td'>"+t+"</td><td class='my_td'>"+failureTime+"</td></tr>");      
            });
            initPageData(data,"pagers");
            $("#dgls").val(0);
            dongj();
        }
    });
    dongj();
}

判断一下你的值是否为undefined,如果为undefined的,就将这个值设置为空

(item.operatorName==undefined?"":item.operatorName)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值