当前位置:网站首页>[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>`
边栏推荐
- Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
- [deep learning] how does deep learning affect operations research?
- 迁移/home分区
- 一键安装脚本实现快速部署GrayLog Server 4.2.10单机版
- 新春限定丨“牛年忘烦”礼包等你来领~
- Which keywords will conflict with the abstract keyword
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- Six common transaction solutions, you sing, I come on stage (no best, only better)
- HiEngine:可媲美本地的云原生内存数据库引擎
- Starkware: to build ZK "universe"
猜你喜欢
随机推荐
抽象类中子类与父类
【漏洞预警】CVE-2022-26134 Confluence 远程代码执行漏洞POC验证与修复过程
The difference between abstract classes and interfaces
ES6 drill down - Async functions and symbol types
21. [STM32] I don't understand the I2C protocol. Dig deep into the sequence diagram to help you write the underlying driver
用键盘输入一条命令
Obj resolves to a set
写单元测试的时候犯的错
RLock锁的使用
视觉体验全面升级,豪威集团与英特尔Evo 3.0共同加速PC产业变革
Pspnet | semantic segmentation and scene analysis
有序链表集合求交集 方法 总结
sql中查询最近一条记录
效果编辑器新版上线!3D渲染、加标注、设置动画,这次一个编辑器就够了
Find the root of the following equation by chord cutting method, f (x) =x^3-5x^2+16x-80=0
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
Apiccloud cloud debugging solution
StarkWare:欲构建ZK“宇宙”
Quelques réflexions cognitives
List uses stream flow to add according to the number of certain attributes of the element








