检查传入数据(Check incoming data)#
有时,你可能想要检查传入的数据。如果传入的数据不符合某个条件,你可能希望返回不同的值。例如,你想检查上一个节点的变量是否为空,如果为空则返回一个字符串。使用以下代码片段,如果变量为空则返回 not found。
🌐 At times, you may want to check the incoming data. If the incoming data doesn't match a condition, you may want to return a different value. For example, you want to check if a variable from the previous node is empty and return a string if it's empty. Use the following code snippet to return not found if the variable is empty.
1 | |
上述表达式使用了三元运算符。你可以在这里了解更多关于三元运算符的信息。
🌐 The above expression uses the ternary operator. You can learn more about the ternary operator here.
作为一种替代方法,你可以使用空值合并运算符 (??)或逻辑或运算符 (||):
🌐 As an alternative, you can use the nullish coalescing operator (??) or the logical or operator (||):
1 2 | |
在上述两种情况下,如果 $x 被设置为非空、非假值,则会使用其值。字符串 default value 是备用值。
🌐 In either of the above two cases, the value of $x will be used if it's set to a non-null, non-false value. The string default value is the fallback value.