I am trying to add an even listener programmatically, to a photoshop plugin using this code:
actionObject = [];
actionObject[0] = {name: "A1", id: "95ce"};
actionObject[1] = {name: "B2", id: "9dk2"};
.
.
actionObject[10] = {name: "H6", id: "9334"};
for (i = 0; i < actionObject.length; i++ ){
console.log("#btn" + actionObject[i].name);
var action = actionObject[i];
$("#btn" + action.name).click(async function () {
await ExecuteAsModal(() => runAction(action));
});
}
The problem I am facing is that when this even is triggered, regardless of the button I am pressing, it always tries to run “runAction” with the last ‘action’ in the actionObject array. In this case it always tries to run it with
action={name: "H6", id: "9334"}
How can Make sure each button runs “actionObject” with it’s proper “action”?