简体   繁体   English

如何在 jQuery on.append() 函数中的值为 NULL 时显示空字符串

[英]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.

相关问题 当日期为 NULL 时如何在文本框中显示空字符串 - How show Empty string in Textbox when Date is NULL x-editable,如何在字符串为空时显示特定值? - x-editable, how to show specific value when string is empty? 输入值为空时显示最后一个字符串? - Show last string when input value is empty? 如何在JS中检查值是否不为空且不为空字符串 - How to check if a value is not null and not empty string in JS 当函数的参数为​​“未定义”或“空”或“”(空字符串)时,如何设置它的默认值? - How to set default value of a parameter of a function when it is 'undefined' or 'null' or ''(empty string)? 当AngularJS中的ng-repeat值为null时如何显示空字符串 - How to display empty string when ng-repeat value is null in angularjs 如果值在 Jquery 中为 null 或为空,则赋值 0 - Assign 0 if the value is null or empty in Jquery 如果为空,则添加/附加查询字符串 - Add/Append query string if empty jquery/javascript 当输入值为空时显示/隐藏输入(jquery,javascript) - show/hide input when input value is empty(jquery, javascript) 如何在提交表单时为空的材质 UI 文本字段提供 null 的值,而不是空字符串? - How can I give an empty material UI text field a value of null, when submitting the form, instead of an empty string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM