之前自己做的一个图书管理系统,显示图书借阅排行榜,因为翻译在数据库中有为空的字段,故前台显示会显示undefined。
以下贴上部门代码:
$(document).ready(function () { $("#rankTable tbody").html(""); var id = 1; $.ajax({ url:"bookInfo/bookInfo_rank.action", type:"POST", data:{}, dataType:"json", success:function (data) { $(data).each(function(i,item) { var index = id++; var bookId = item.bookId; var bookName = item.bookName; var author = item.author; //判断是否为空出现undefined; var translator = (item.translator==undefined ?"":item.translator); var ISBN = item.ISBN; var press = item.press; var page = item.page; var bookCase = item.bookCase; var totalNum = item.totalNum; var stock = item.stock; var borrowNum = item.borrowNum; var typeName = item.typeName; var str = '' + ' '; $("#rankTable tbody").append(str); str = ""; }) }, error:function(XMLHttpRequest, textStatus, errorThrown){ alert("系统异常,请稍后重试!"); alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }) });' + index + ' ' + '' + bookId + ' ' + '' +bookName + ' ' + '' + author+ ' ' +''+translator+ ' ' +''+ISBN+ ' ' +''+press+ ' ' +''+page+ ' ' +''+bookCase+ ' ' +''+totalNum+ ' ' +''+stock+ ' ' +''+borrowNum+ ' ' +''+typeName+ '