Root(全局变量与函数)
$()
说明: 返回指定节点的数据。
语法: $(nodeName)
返回值: NodeData
来源: n8n 自定义功能
参数:
nodeName(String)— 要获取数据的节点名称。
$binary
说明: 返回当前节点中当前数据项的二进制输入数据,是 $input.item.binary 的简写。
语法: $binary
返回值: Array
来源: n8n 自定义功能
$execution
说明: 获取或设置当前执行的元数据。
语法: $execution
返回值: ExecData
来源: n8n 自定义功能
$fromAI()
说明: 当节点参数的值应由大语言模型提供时使用。建议提供说明,以获得更好的结果。
语法: $fromAI(key, description?, type?, defaultValue?)
返回值: any(任意类型)
来源: n8n 自定义功能
参数:
key(String)— 要获取的字段名,仅允许包含字母、数字、下划线和连字符。description(String)— 可选 — 向模型提供更多上下文,说明它具体应返回什么内容。type(String)— 可选 — 返回值的类型。可选值为string、number、boolean、json、date、datetime。默认为string。defaultValue(any)— 可选 — 模型未返回该键时使用的值。
示例:
// Ask the model to provide a name, and use it here
$fromAI('name')
// Ask the model to provide the age of the person (as a number with a default value of 18), and use it here
$fromAI('age', 'The age of the person', 'number', 18)
// Ask the model to provide a boolean signifying whether the person is a student (with default value false), and use it here
$fromAI('isStudent', 'Is the person a student', 'boolean', false)
$if()
说明: 根据 condition 返回两个值中的一个,与 JavaScript 的 ? 运算符类似。
语法: $if(condition, valueIfTrue, valueIfFalse)
返回值: any(任意类型)
来源: n8n 自定义功能
参数:
condition(Boolean)— 要检查的条件,求值结果应为true或false。valueIfTrue(any)— 条件为 true 时返回的值。valueIfFalse(any)— 条件为 false 时返回的值。
示例:
// Return "Good day" if time is before 5pm, otherwise "Good evening"
$if($now.hour < 17, "Good day", "Good evening")
// $if() calls can be combined:
// Return "Good morning" if time is before 10am, "Good day" it's before 5pm, otherwise "Good evening"
$if($now.hour < 10, "Good morning", $if($now.hour < 17, "Good day", "Good evening"))
$ifEmpty()
说明: 如果第一个参数不为空,则返回第一个参数,否则返回第二个参数。以下值视为空:””、[]、{}、null、undefined。
语法: $ifEmpty(value, valueIfEmpty)
返回值: any(任意类型)
来源: n8n 自定义功能
参数:
value(any)— 非空时要返回的值。valueIfEmpty(any)—value为空时返回的值。
示例:
"Hi " + $ifEmpty(name, "there") // e.g. "Hi Nathan" or "Hi there"
$input
说明: 当前节点的输入数据。
语法: $input
返回值: NodeData
来源: n8n 自定义功能
$itemIndex
说明: 当前正在处理的数据项在输入数据项列表中的位置。
语法: $itemIndex
返回值: Number(数字)
来源: n8n 自定义功能
$jmespath()
说明: 使用 JMESPath 表达式从对象或对象数组中提取数据,适合查询复杂的嵌套对象。如果表达式无效,则返回 undefined。
语法: $jmespath(obj, expression)
返回值: any(任意类型)
来源: n8n 自定义功能
参数:
obj(Object|Array)— 要从中获取数据的对象或对象数组。expression(String)— 定义要从对象中获取哪些数据的 JMESPath 表达式。
示例:
data = {
"people": [
{
"age": 20,
"other": "foo",
"name": "Bob"
},
{
"age": 25,
"other": "bar",
"name": "Fred"
},
{
"age": 30,
"other": "baz",
"name": "George"
}
]
}
// Get all names, in an array
{{ $jmespath(data, '[*].name') }} //=> ["Bob", "Fred", "George"]
// Get the names and ages of everyone under 20
$jmespath(data, '[?age > `20`].[name, age]') //=> [ ["Fred",25], ["George",30] ]
// Get the name of the first person under 20
$jmespath($json.people, '[?age > `20`].name | [0]') //=> Fred
data = {
"reservations": [
{
"id": 1,
"guests": [
{
"name": "Nathan",
"requirements": {
"room": "double",
"meal": "vegetarian"
}
},
{
"name": "Meg",
"requirements": {
"room": "single"
}
}
]
},
{
"id": 2,
"guests": [
{
"name": "Lex",
"requirements": {
"room": "double"
}
}
]
}
]
}
// Get the names of all the guests in each reservation that require a double room
$jmespath(data, 'reservations[].guests[?requirements.room==`double`].name')
$json
说明: 返回当前节点中当前数据项的 JSON 输入数据,是 $input.item.json 的简写。更多信息