You need to sign in to do that
Don't have an account?
Debabrata Bera
How to Iterate one cmp inside another cmp
I have following scenario where i have two set of cmp from js. now i want to iterate one cmp under another cmp based on id.
Apex Class Method:
public static ContactListWrapper getContacts(Id recordId) {
List<Contact> contactList=new List<Contact>();
List<OpportunityContactRole> ocrList;
List<OpportunityContactRole> ocrListFull=new List<OpportunityContactRole>();
Opportunity opp = [SELECT AccountId FROM Opportunity where Id =:recordId];
contactList = [SELECT Id, Name, Email, Phone, MobilePhone From Contact Where AccountId =:opp.AccountId ORDER BY Name];
for(Contact con : contactList) {
ocrList = [SELECT Id, ContactId, Role, isPrimary from OpportunityContactRole where ContactId =:con.id];
for(OpportunityContactRole ocr : ocrList)
ocrListFull.add(ocr);
}
return new ContactListWrapper(contactList,ocrListFull);
}
in Controller.js-
component.set("v.items", result);
in .cmp-
<tbody>
<aura:iteration items="{!v.items}" var="item">
<aura:iteration items="{!item.contactList}" var="con"> --> For Contact record
<tr>
<td data-label="Name">
{!con.Name}
</td>
<td data-label="Phone">
<lightning:clickToDial value="{!con.Phone}" />
</td>
<td data-label="Mobile">
<lightning:clickToDial value="{!con.MobilePhone}" />
</td>
<td data-label="Email">
<lightning:formattedEmail value="{!con.Email}" />
</td>
<td data-label="Role">
* I want to display Role here which is present in ocrListFull based on contactId of contactList.
</td>
</tr>
</aura:iteration>
</aura:iteration>
Please let me know if anyone have suitable solution.
Apex Class Method:
public static ContactListWrapper getContacts(Id recordId) {
List<Contact> contactList=new List<Contact>();
List<OpportunityContactRole> ocrList;
List<OpportunityContactRole> ocrListFull=new List<OpportunityContactRole>();
Opportunity opp = [SELECT AccountId FROM Opportunity where Id =:recordId];
contactList = [SELECT Id, Name, Email, Phone, MobilePhone From Contact Where AccountId =:opp.AccountId ORDER BY Name];
for(Contact con : contactList) {
ocrList = [SELECT Id, ContactId, Role, isPrimary from OpportunityContactRole where ContactId =:con.id];
for(OpportunityContactRole ocr : ocrList)
ocrListFull.add(ocr);
}
return new ContactListWrapper(contactList,ocrListFull);
}
in Controller.js-
component.set("v.items", result);
in .cmp-
<tbody>
<aura:iteration items="{!v.items}" var="item">
<aura:iteration items="{!item.contactList}" var="con"> --> For Contact record
<tr>
<td data-label="Name">
{!con.Name}
</td>
<td data-label="Phone">
<lightning:clickToDial value="{!con.Phone}" />
</td>
<td data-label="Mobile">
<lightning:clickToDial value="{!con.MobilePhone}" />
</td>
<td data-label="Email">
<lightning:formattedEmail value="{!con.Email}" />
</td>
<td data-label="Role">
* I want to display Role here which is present in ocrListFull based on contactId of contactList.
</td>
</tr>
</aura:iteration>
</aura:iteration>
Please let me know if anyone have suitable solution.