component.find an aura:id item created in aura:iteration
aura:id
must be a literal value. As such, you can't use an expression in aura:id
(it will be treated as literal text). Instead, you can use the element's id
via document.getElementById
:
var selectedItemNew = document.getElementById(oppId);
First problem is that we cannot use expression while assigning aura:id. Aura:id need to be static.
so your first change is
<a href="javascript:void(0);" role="menuitem" tabindex="-1" id="{!opp.Id}" onclick="{!c.openItemFromMenu}" aura:id="link">
in js you can do
openItemFromMenu: function(component, event, helper) {
// get the id from the event
var oppId = event.getParam("recordId");
// choose it (select menu)
var selectedItemsNew = component.find('link').getElements();
if(Array.isArray(selectedItemsNew)){
var selectedItemNew = selectedItemsNew.find(function (oneItem){
return oppId === selectedItemsNew.id})
if(selectedItemNew){
selectedItemNew.style = "background: rgb(216, 237, 255);"
}
} else if(selectedItemsNew){
if(oppId === selectedItemsNew.id){
selectedItemNew.style = "background: rgb(216, 237, 255);"
}
}
}
Instead of adding style directly you can create a class and use
$a.util.addclass()
I don't know if it will work for you, but what worked for me was just assigning the same static aura:id to each element in the iteration, and then when you use component.find() it will return an array of all the elements.