绑定数据如果后台有null,用三元运算符

来源:互联网 发布:excel数据库教程 编辑:程序博客网 时间:2024/05/21 17:35
'<p class="prize-tel fl other-break">' + ((result[i].phone === null) ? take_p_html : result[i].phone)+ '</p>'

//这样就可以在循环时直接把null改写了(估计性能上肯定有缺失)。take_p_html是我设定的一个常量,如果是null那么我就把设定为一个常量字符串( (result[i].phone === null) ? take_p_html : result[i].phone )

注意一定要用() 把这个三元语句括上不然会报错,而且这个 result[i].phone === null 外面也需要一个括号

原创粉丝点击