[SalesForce] aura:if inside aura:iteration

I want to conditionally render each item in an iterating list. It has to check if each contact in the iterating list is included/contains in another list of contacts. How should I approach ?


<aura:component access="global">
  <aura:attribute name="contactList" type="Object[]"/>
  <aura:attribute name="wspContactIds" type="String[]"/>
  <aura:attribute name="evaluated" type="Boolean" default="false"/>

   <aura:iteration var="ctct" items="{!v.contactList}">
        <div class="slds-media__body">
        <div class="slds-no-flex">   
           <button id="{!'reEvaluate'+ ctct.Id}" class="{!v.evaluated ==true ? 'slds-button': 'hide slds-button'}" onclick="{!c.reevaluate}"><b>Re-Evaluate</b> </button> 
           <button id="{!'evaluate'+ ctct.Id}" class="{!v.evaluated ==true ? 'hide slds-button': ' slds-button'}" onclick="{!c.evaluate}"><b>Evaluate</b> </button>         



 doInit : function(component,event,helper){
   var secondContactList= component.get("v.wspContact");
   var firstContactList = component.get("v.contactList");
   for(var i=0; i<firstContactList .length;i++){
       for(var j=0; j<secondContactList.length;j++){
           if(firstContactList[i].Id == secondContactList[j].Id){ 



Like shown below, I need to identify the already evaluated contact item and its corresponding button needs to be changed.
Iterating List

Best Answer

Are you trying to run the list only for the Contact Ids which are included in the list.

You can include them in the list by creating null check in the apex controller. Or you can check them in the Javascript controller. Suppose lets assume that you are trying to return a Wrapper list. Forgive me for my syntax. this is just a code snippet. Use as per your convenience.


public class Sample(){
    global static string getWrapperValues(){
        List<ContactWrap> wrapList = new list<ContactWrap>();

        for(Contact c : your list){ // run your contactlist
        ContactWrap cw = new ContactWrap();
        cw.theContact = c;
    return JSON.serialize(wrapList);
public list ContactWrap{
    public Contact theContact {get;set;}

js Controller :

    doInit : function(Component){
        var action = component.get("c.getWrapperValues");

        // set your params for action if any 

            var output = response.getReturnValue();
            var wrapper = JSON.parse(output);
            for(var i=0;i<wrapper.length;i++){
                var arrVar = wrapper[i];
                    // set your list 
                    // show custom errors
Related Topic