[英]Does Lightning Web Component IF Directive support multiple conditions?
Hi I am new to LWC world & its syntax.嗨,我是 LWC 世界及其语法的新手。 I wanted to ask, if LWC supports multiple condition in a single statement?我想问一下,LWC 是否支持单个语句中的多个条件?
Ex:前任:
<template if:true={condition1 == 'value1' && condition2 == 'value2'}></template>
Getting Error on using multiple conditions on single line statement.在单行语句上使用多个条件时出错。
or should go for below approach或者应该采用以下方法
html - <template if:true={validateCondition}></template>
class js file - get validateCondition() { return (condition1 == 'value1' && condition2 == 'value2');}
Or have to use nested conditions或者必须使用嵌套条件
<template if:true={condition1 == 'value1'}>
<template if:true={condition2 == 'value2'}>
</template>
</template>
Current using above statement当前使用上述语句
Option 2. Keep html clean.选项 2. 保持 html 干净。 The decisions to show/hide parts of page are part of your business logic, should be kept in JS with other calculations.显示/隐藏页面部分的决定是您业务逻辑的一部分,应与其他计算一起保存在 JS 中。 That'd also make it testable.这也使它可测试。 I don't think you even can do option 3, I expect it to fail on compilation?我认为您甚至无法执行选项 3,我希望它在编译时失败?
You can't use formulas in these or anything computed, only straight properties and getters.您不能在这些或任何计算中使用公式,只能使用直接属性和 getter。 https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_directives https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_directives
Migration guide might help too: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.migrate_expressions迁移指南也可能有所帮助: https : //developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.migrate_expressions
Answer to this one is cool too: https://salesforce.stackexchange.com/q/249293/799这个答案也很酷: https : //salesforce.stackexchange.com/q/249293/799
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.