Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lucee 5.x ListEach doesn't seem to be able to access local var scope?

I can't seem to access the local scope within my ListEach:

writeDump(local.woCoreID); // outputs expected values
//  LOOP OVER LIST AND SEPARATE TEXT FROM INTEGERS
ListEach(local.__userSuppliedWorkoutTagList, function (item) {
    writeDump(item) //  outputs expected values
    writeDump(local.woCoreID); // key [woCoreID] doesn't exist
});

when I try to access the local.woCoreID, I get an error message, key [woCoreID] doesn't exist. Why is that when I can dump it before the ListEach and I see the value is there. What am I missing here?

I'm using Lucee 5.x

like image 805
HPWD Avatar asked Mar 05 '23 09:03

HPWD


1 Answers

Each function has its own local scope. If you want to the outer scope, you must make a reference to it:

var outerLocal = local;

ListEach(local.__userSuppliedWorkoutTagList, function (item) {
    writeDump(item);
    writeDump(outerLocal.woCoreID);
});

or use a regular, counted for loop instead of ListEach() + function.

like image 78
Tomalak Avatar answered May 01 '23 18:05

Tomalak