当前位置:网站首页>[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>`
边栏推荐
- Replknet: it's not that large convolution is bad, but that convolution is not large enough. 31x31 convolution. Let's have a look at | CVPR 2022
- APICloud云调试解决方案
- 给自己打打气
- 五种常见的咨询公司谈判策略以及如何维护自己的利益
- 今日睡眠质量记录79分
- [Netease Yunxin] research and practice of super-resolution technology in the field of real-time audio and video
- ES6 deep - ES6 class class
- 16. [stm32] starting from the principle, I will show you the DS18B20 temperature sensor - four digit digital tube displays the temperature
- 不敢买的思考
- 极坐标扇图使用场景与功能详解
猜你喜欢
随机推荐
单商户 V4.4,初心未变,实力依旧!
StarkWare:欲构建ZK“宇宙”
Transaction rollback exception
Dataarts studio data architecture - Introduction to data standards
Cartoon: what is service fusing?
Find the root of the following equation by chord cutting method, f (x) =x^3-5x^2+16x-80=0
Domestic API management artifact used by the company
移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理
项目中批量update
10 minutes to help you get ZABBIX monitoring platform alarm pushed to nail group
Query the latest record in SQL
单商户 V4.4,初心未变,实力依旧!
Apple 已弃用 NavigationView,使用 NavigationStack 和 NavigationSplitView 实现 SwiftUI 导航
新春限定丨“牛年忘烦”礼包等你来领~
Cartoon: what is the eight queens problem?
[Netease Yunxin] research and practice of super-resolution technology in the field of real-time audio and video
Research and practice of super-resolution technology in the field of real-time audio and video
This article takes you through the addition, deletion, modification and query of JS processing tree structure data
2020-2022两周年创作纪念日