This version is out of date, covering development from v9.0.0 to v9.3.0. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

eachLink(LoopVar){action}


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 Item   [operators of similar scope]

 Linking   [other Linking operators]

 9.1.0

 9.3.0


eachLink(LoopVar){}

New to v9.1.0, this operator examines each link for the current note, either inbound or outbound; prototype links are excluded. The local, user-set, variable LoopVar is bound to a dictionary-type object of per-link properties, including:

The above features are described for the Browse Links or the Links Inspector.

Count, first and list tests

Although eachLinks is functionally like a list iterator (i.e. List.each()) it works off a dynamically generated List but the LoopVar is bound to each list item's Dictionary. This means the list object properties of List.count, List.first and List.last are not available.

The count of the links iterated for a given note by eachLink() is $OutboundLinkCount plus $InboundLinkCount:

var:number vLkCt = $OutboundLinkCount plus $InboundLinkCount;

From v9.3.0, LoopVar now supports two dot-operators:

In effect this mimics List.first and List.last tests as used in each() but here for eachlink(). This the following example the first if() uses the long form test for a boolean true, the second the short form—both give the same result:

	eachLink(aLink){
		if(aLink.isFirst==true){
			//this is the first link in the listing;
		};
		if(aLink.isLast){
			//this is the last link in the listing;
		};
       	};

Why might this be used? If the links are being processed so as to only export certain typed links, it may be necessary to add additional text/styling before the first and after the last link.

eachLink() is read-only: any changes to these exposed per-link key values are not (yet) recorded as changes to the link, i.e. the link's settings cannot be changed using eachLink().

More examples

Does this note have a link of type "agree"?

	function isAgreeable(){
		eachLink(aLink) {
			if(aLink["type"]=="agree"){
				return true;
			};
        	};
		return false;
 	};

Or, to count the number of links from this note to tasks:

	function linkedTasks(){
		var:number vCount=0;
		eachLink(aLink){
			if($Prototype(aLink["destination"])=="Task"){
				vCount += 1;
			};
		};
		return count;
	};

The examples use line breaks for clarity, and the last example may equally well be stored and used in the form:

function linkedTasks(){var:number vCount=0;eachLink(aLink){if($Prototype(aLink["destination"])=="Task"){vCount+=1;};};return count;};