[英]How to show empty string when value is NULL in jQuery on .append() funtion
I need to set html value using.append() funtion, so i need to set ajex data values on it.我需要使用.append() 函数设置 html 值,所以我需要在其上设置 ajex 数据值。 if data set contain null value then showing as 'null' in UI.如果数据集包含 null 值,则在 UI 中显示为“null”。 i need remove that 'null' With blank.我需要用空白删除那个'null'。
But can't use separate if funtions before the.append().但不能在.append() 之前使用单独的 if 函数。 because have to show many separate values on it, S i Want remove null value on when showing 'null' .因为必须在上面显示许多单独的值,所以我想在显示'null'时删除 null 值。
How can i remove this 'null' when showing the value?显示值时如何删除此“null”?
$('#diagnosis').append(' <div class="row">\n' +
' <div class="col-sm-1" >\n' +
' </div>\n' +
' <div class="col-sm-2"><label>Mobile</label>\n' +
' <div class="col-sm-9"> ' + data.person.tp+ ' \n' +
' </div>\n' +
' </div>\n' +
' <div class="row">\n' +
' <div class="col-sm-1">\n' +
' </div>\n' +
' <div class="col-sm-2"><label>Address</label></div>\n' +
' <div class="col-sm-9"> ' + data.person.address + ' \n' +
' </div>\n' +
' </div>');
Since null
is "falsey", you can use an or to replace a null
value with a default string, for example:由于null
为“假”,您可以使用 或 将null
值替换为默认字符串,例如:
'<div class="col-sm-9"> ' + (data.person.tp || '') + ' \n' +
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.