如何在文本属性中使用 if else 来显示一个值或另一个值? [英] How to use if else in text property to display either one value or another?

查看:32
本文介绍了如何在文本属性中使用 if else 来显示一个值或另一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个不同的值,例如 QtValidFDocDate,我希望能够显示 DocDate 仅当 QtValidF 来自 null.我怎么能这样呢?

Having two distinct values such as QtValidF and DocDate, I want to be able to display DocDate only if QtValidF comes null. How could I condition this?

<Text text="{
  path: 'QtValidF',
  formatter:'.formatoFecha'
}"/>

我正在尝试此操作,但不起作用.

I'm trying this but doesn't work.

<Text text="{= ${QtValidF} != 'null' ? {
  path: 'DocDate',
  formatter: '.formatoFecha'
} : {
  path: 'QtValidF',
  formatter: '.formatoFecha'
}}"/>

推荐答案

表达式绑定

通常,您可以将表达式绑定用于<强>简短的条件表达式.

<MyControl anyProperty="{= ${myPrimary} || ${mySecondary}}" />

就像在 JS 中一样,当第一个操作数的结果是 falsy值,考虑第二个.

Just like in JS, when the first operand results in one of the falsy values, the second one is taken into account.

如果 首选格式化程序,可以使用复合绑定语法:

In case a formatter is preferred, the composite binding syntax can be used:

<MyControl anyProperty="{
  parts: [
    'myPrimary',
    'mySecondary'
  ],
  formatter: '.getThatValue'
}" />

然后在控制器中:

getThatValue: function(primaryValue, secondaryValue) {
  return primaryValue || secondaryValue;
},

有关更多信息,请查看主题绑定语法复合绑定.

For more information, please take a look at the topics Binding Syntax and Composite Binding.

这篇关于如何在文本属性中使用 if else 来显示一个值或另一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆