Skip to content

Programmatic-style parameters#

นี่คือ parameters ที่ใช้ได้กับ node base file ของ programmatic-style nodes

เอกสารนี้จะมีโค้ดตัวอย่างสั้น ๆ เพื่อช่วยให้เข้าใจโครงสร้างและแนวคิด ถ้าต้องการดูตัวอย่างจริงแบบเต็ม ๆ ดูที่ Build a programmatic-style node

node แบบ programmatic-style จะต้องมี method execute() ด้วย ดูรายละเอียดเพิ่มเติมที่ Programmatic-style execute method

ดู parameters ที่ใช้ได้กับ node ทุกประเภทได้ที่ Standard parameters

defaultVersion#

Number | Optional

ใช้ defaultVersion เมื่อใช้วิธี versioning แบบเต็ม

n8n รองรับ 2 วิธีการ versioning ดูรายละเอียดที่ Node versioning

methods and loadOptions#

Object | Optional

object นี้จะมี method loadOptions สำหรับ programmatic-style node สามารถใช้ method นี้เพื่อ query ข้อมูลจาก service เช่นดึงค่าต่าง ๆ ที่ user มี แล้วแสดงใน GUI ให้ user เลือกใช้ใน query ต่อไป

ตัวอย่างเช่น Gmail node ของ n8n ใช้ loadOptions เพื่อดึง labels ทั้งหมด:

 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
	methods = {
		loadOptions: {
			// Get all the labels and display them
			async getLabels(
				this: ILoadOptionsFunctions,
			): Promise<INodePropertyOptions[]> {
				const returnData: INodePropertyOptions[] = [];
				const labels = await googleApiRequestAllItems.call(
					this,
					'labels',
					'GET',
					'/gmail/v1/users/me/labels',
				);
				for (const label of labels) {
					const labelName = label.name;
					const labelId = label.id;
					returnData.push({
						name: labelName,
						value: labelId,
					});
				}
				return returnData;
			},
		},
	};

version#

Number หรือ Array | Optional

ถ้ามีแค่ 1 version ของ node ให้ใช้เป็นตัวเลขเดียว ถ้าต้องการรองรับหลาย version ให้ใช้ array ที่มีเลข version แต่ละอัน

n8n รองรับ 2 วิธีการ versioning node แบบ programmatic-style ใช้ได้ทั้งสองแบบ ดูรายละเอียดที่ Node versioning