简体   繁体   English

Lightning Web 组件 IF 指令是否支持多个条件?

[英]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.

相关问题 显示 JSON 字符串的 Lightning Web 组件不起作用 - Lightning Web Component to display JSON String is not working Lightning Web 组件设置动态样式未按预期工作 - Lightning Web Component setting dynamic style not working as expected 401 未经授权 REST API 中闪电 web 组件 ZA8FF6C9514C35C8563B350382 - 401 Unauthorized REST API in lightning web component salesforce 在没有顶点的闪电 web 组件上创建任务仅 javascript controller? - Create a task on a lightning web component without apex only javascript controller? 输入有效的 URL 并重试: Salesforce Lightning Web 组件错误 - Enter a valid URL and try again : Salesforce Lightning Web Component Error 如何在 Visual Force Pages 中使用 Lightning Web 组件? - How to use Lightning Web Component inside Visual Force Pages? 使用 Charts Js 在 Lightning Web 组件中将数据从父级传递给子级 - Pass data from parent to child in lightning web component using Charts Js 如何在操场上将一些简单的 styles 应用于闪电 web 组件的“数据表”的 tds? - How to apply some simple styles to tds of “datatable” of lightning web component in playground? 在闪电组件中显示 csv 数据 - Show csv data in lightning component DotNetBrowser是否支持网络工作者? - Does DotNetBrowser support web workers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM