Tinderbox Forum

How does eachLink(LoopVar){} work?

Does someone have an example of how to make this work? eachLink(LoopVar){}? When would you use it?

eachLink(x){…}
Examines each link, either inbound or outbound to this note, with the exception of prototype links. The local variable x is bound to a dictionary of link properties, include source, destination, type, class, title, target, url, comment, and anchor. Changes to this variables values are not (yet) recorded as changes to the link.

For example, does this note have a link of type “agree”?

function isAgreeable() {
     eachLink(x) {
        if(x.type=="agree") {return true;}
        };
     return false;
     }

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

function linkedTasks() {
    var:number count=0;
    eachLink(x) {
        if($Prototype(x.destination)=="Task") {count += 1;}
        };
    return count;
1 Like

Thanks. @mwra, this would be a nice example for aTbRef.

@satikusala’s suggestion actioned, see my article on eachLink(LoopVar).