InfoGrab DocsInfoGrab Docs

Code node에서 연결된 항목에 접근하기

노드 입력 데이터의 모든 항목은 해당 항목을 생성하는 데 사용된 이전 노드의 항목으로 다시 연결됩니다. 이는 바로 이전 노드보다 더 앞선 노드에서 연결된 항목을 가져와야 할 때 유용합니다. 워크플로에서 더 앞서 있는 연결된 항목에 접근하려면 ("<node-name>").itemMatching(currentNodeinputIndex) 를 사용하세요. 예를 들어, 다음과 같은 작업을 수행하는 워크플로가 있다고 가정해 보겠습니다. Customer Datastore 노드가 다음과 같은 예제 데이터를 생성합니다. [ { "id" : "23423532" , "name" : "Jay Gatsby" , "email" : "gatsby@west-egg.com" , "notes" : "Keeps asking about a green light??" , "country" : "US" , "created" : "1925-04-10" } , { "id" : "23423533" , "name" : "José Arcadio Buendía" , "email" : "jab@macondo.co" , "notes" : "Lots of people named after him. Very confusing" , "country" : "CO" , "created" : "1967-05-05" } , ... ] Edit Fields 노드가 이 데이터를 단순화합니다. [ { "name" : "Jay Gatsby" } , { "name" : "José Arcadio Buendía" } , ... ] Code node가 올바른 사람에게 이메일 주소를 복원합니다. [ { "name" : "Jay Gatsby" , "restoreEmail" : "gatsby@west-egg.com" } , { "name" : "José Arcadio Buendía" , "restoreEmail" : "jab@macondo.co" } , ... ] Code node는 다음 코드를 사용하여 이 작업을 수행합니다. JavaScript for ( let i= 0 ; i<$input. all (). length ; i++) { $input. all ()[i]. json . restoreEmail = $( 'Customer Datastore (n8n training)' ). itemMatching (i). json . email ; } return $input. all (); Python for i,item in enumerate (_ input . all ()): _ input . all ()[i].json.restoreEmail = _( 'Customer Datastore (n8n training)' ).itemMatching(i).json.email return _ input . all (); 예제 워크플로는 n8n website | itemMatching usage example 에서 확인하고 다운로드할 수 있습니다.