跳至内容

声明式风格参数#

这些是node base file声明式节点可用的参数。

本文档提供简短的代码片段,帮助理解代码结构和概念。如需完整了解构建节点的步骤(包含实际代码示例),请参阅构建声明式节点

请参考标准参数查看所有节点可用的参数。

methodsloadOptions#

对象 | 可选

methods 包含 loadOptions 对象。您可以使用 loadOptions 查询服务以获取用户特定设置,然后返回这些设置并在图形界面中呈现,以便用户可以将它们包含在后续查询中。该对象必须包含用于查询服务的路由信息,以及定义如何处理返回选项的输出设置。例如:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
methods : {
	loadOptions: {
		routing: {
			request: {
				url: '/webhook/example-option-parameters',
				method: 'GET',
			},
			output: {
				postReceive: [
					{
						// When the returned data is nested under another property
						// Specify that property key
						type: 'rootProperty',
						properties: {
							property: 'responseData',
						},
					},
					{
						type: 'setKeyValue',
						properties: {
							name: '={{$responseItem.key}} ({{$responseItem.value}})',
							value: '={{$responseItem.value}}',
						},
					},
					{
						// If incoming data is an array of objects, sort alphabetically by key
						type: 'sort',
						properties: {
							key: 'name',
						},
					},
				],
			},
		},
	}
},

routing#

对象 | 必填

routing 是一个用于操作和输入字段对象中 options 数组的对象。它包含API调用的详细信息。

以下代码示例来自声明式风格教程。它设置了与NASA API的集成。展示了如何使用requestDefaults来配置基本的API调用详情,以及routing为每个操作添加信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
description: INodeTypeDescription = {
  // Other node info here
  requestDefaults: {
			baseURL: 'https://api.nasa.gov',
			url: '',
			headers: {
				Accept: 'application/json',
				'Content-Type': 'application/json',
			},
		},
    properties: [
      // Resources here
      {
        displayName: 'Operation'
        // Other operation details
        options: [
          {
            name: 'Get'
            value: 'get',
            description: '',
            routing: {
              request: {
                method: 'GET',
                url: '/planetary/apod'
              }
            }
          }
        ]
      }
    ]
}

version#

数值数组 | 可选

如果您的节点只有一个版本,这里可以填写一个数字。如果您想支持多个版本,请将其转换为数组,包含每个节点版本对应的数字。

n8n支持两种节点版本控制方法,但声明式节点必须使用轻量级版本控制方式。更多信息请参阅Node versioning

优云智算