后台传过来一个集合,其中有的值为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)