前台显示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("+status+" onclick='check(this)' id='ck"+index+"' name='ck' value='"+item.id+"'>"+item.bak2+""+s+""+gmtCreate+""+item.moduleNumber+""+(item.vendorDesc==undefined?"":item.vendorDesc)+""+(item.danhao==undefined?"":item.danhao)+""+(item.operatorName==undefined?"":item.operatorName)+""+t+""+failureTime+"");      
            });
            initPageData(data,"pagers");
            $("#dgls").val(0);
            dongj();
        }
    });
    dongj();
}

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

(item.operatorName==undefined?"":item.operatorName)

你可能感兴趣的:(jQuery,ajax)