Skip to content

检查传入数据#

¥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.

{{$json["variable_name"]? $json["variable_name"] :"not found"}}

以上表达式使用了三元运算符。你可以在 此处 页面上了解更多关于三元运算符的信息。

¥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 (||):

{{ $x ?? "default value" }} {{ $x || "default value" }}

在上述两种情况下,如果 $x 的值设置为非空或非 false,则会使用该值。字符串 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.