当前位置:网站首页>[es6] add if judgment or ternary operator judgment in the template string
[es6] add if judgment or ternary operator judgment in the template string
2022-07-05 16:28:00 【533_】
Add if Judge or add ternary operators to judge
es6 Template string example :
var html = `<div class="a2"> <p>1</p> <p>2</p> <p>3</p> <p>4</p> </div>`
Add if Judge
var html = `<div class="a2"> <p>1</p> <p>2</p> <p>3</p> <p> ${
(function(){
if(XXXXXXXXX){
// Conditions return `XXXX`; }else{
return ''; } })() } </p> </div>`
- Don't forget to be in function After that, add another (), Otherwise, it will be parsed directly according to the string
- If you return a dynamic data, remember
return ``, If you usereturn ''It will also be directly parsed into strings
Don't forget to be in function After that, add another (), Otherwise, it will be parsed directly according to the string
If you return a dynamic data, remember return ``, If you use return '' It will also be directly parsed into strings
// Judge to add class name
var html = `<div class="a2">
<p>1</p>
<p>2</p>
<p>3</p>
<p ${
data[i].aaa ? 'class="hidden"' : ''></p>
</div>`
// Judge the state
var html = `<div class="a2"> <p>1</p> <p>2</p> <p> ${
data[i].status == '0' ? ' Free ' : data[i].status == '1' ? ' Not idle ' : data[i].status == '2' ? ' complete ' : ' Not finished '} </p> <p>4</p> </div>`
边栏推荐
- 一键安装脚本实现快速部署GrayLog Server 4.2.10单机版
- 服务器的数据库连不上了2003,10060“Unknown error“【服务已起、防火墙已关、端口已开、netlent 端口不通】
- Some cognitive thinking
- Is it safe for Guotai Junan to open an account online
- ES6 deep - ES6 class class
- 移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
- Today's sleep quality record 79 points
- RLock锁的使用
- vant popup+其他组件的组合使用,及避坑指南
- The difference between abstract classes and interfaces
猜你喜欢

新春限定丨“牛年忘烦”礼包等你来领~

项目sql中批量update的时候参数类型设置错误

用键盘输入一条命令

Single merchant v4.4 has the same original intention and strength!

Six common transaction solutions, you sing, I come on stage (no best, only better)

Reduce the cost by 40%! Container practice of redis multi tenant cluster

PSPNet | 语义分割及场景分析

Mistakes made when writing unit tests

Flet教程之 12 Stack 重叠组建图文混合 基础入门(教程含源码)

2020-2022两周年创作纪念日
随机推荐
漫画:什么是MapReduce?
中间表是如何被消灭的?
求解汉诺塔问题【修改版】
Single merchant v4.4 has the same original intention and strength!
Six common transaction solutions, you sing, I come on stage (no best, only better)
abstract关键字和哪些关键字会发生冲突呢
How to use FRP intranet penetration +teamviewer to quickly connect to the intranet host at home when mobile office
Cartoon: what is blue-green deployment?
Subclasses and superclasses of abstract classes
开发中Boolean类型使用遇到的坑
移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
搜索 正排索引 和 倒排索引 区别
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
Background system sending verification code function
list集合根据对象某属性求和,最大值等
漫画:什么是八皇后问题?
List de duplication and count the number
Query the latest record in SQL
tf.sequence_mask函数讲解案例
抽象类中子类与父类