function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dharmesh Jagetia 7Dharmesh Jagetia 7 

I want to iterate this table dynamically rather than hardcode on lightning component to take input in lookup field

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="contact1" type="Contact" 
               default="{ 'sobjectType': 'Contact' }"/>
    <aura:attribute name="contact2" type="Contact" 
               default="{ 'sobjectType': 'Contact' }"/>
    <aura:attribute name="contact3" type="Contact" 
               default="{ 'sobjectType': 'Contact' }"/>
    <aura:attribute name="contact4" type="Contact" 
               default="{ 'sobjectType': 'Contact' }"/>
   
   
    <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
        <thead>
            <tr class="slds-text-heading_label">
                <th scope="col"><div class="slds-truncate" title="number"></div></th>
                <th scope="col"><div class="slds-truncate" title="ID">NAme</div></th>
                    <th scope="col"><div class="slds-truncate" title="Name">Lst anesdjsalk</div></th>
                    <th scope="col"><div class="slds-truncate" title="Type">lksdnasdkjds</div></th>
                </tr>
            
            </thead>
        <table>
            <tr>
                <td>
                    <force:inputField value="{!v.contact1.LastName}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact1.AccountId}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact1.Email}"/>
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td>
                    <force:inputField value="{!v.contact2.LastName}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact2.AccountId}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact2.Email}"/>
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td>
                    <force:inputField value="{!v.contact3.LastName}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact3.AccountId}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact3.Email}"/>
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td>
                    <force:inputField value="{!v.contact4.LastName}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact4.AccountId}"/>
                </td>
                <td>
                    <force:inputField value="{!v.contact4.Email}"/>
                </td>
            </tr>
        </table>
    </table>
    <lightning:button type="submit" label="NDC Verify" class="slds-float--right">
    </lightning:button>
</aura:component>
Manish ArvindManish Arvind
Hi Dharmesh,
you can use 1 attribute for list of contacts in place of 4 attributes for 4 Contacts. Then further you can use iteration.

<aura:attribute name="contacts" type="Contact[]" />

If you have further query, please let me know.

-Manish
Manish ArvindManish Arvind
So, You can reduce your code as
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="contacts" type="Contact[]" />
      
    <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
        <thead>
            <tr class="slds-text-heading_label">
                <th scope="col"><div class="slds-truncate" title="number"></div></th>
                <th scope="col"><div class="slds-truncate" title="ID">NAme</div></th>
                    <th scope="col"><div class="slds-truncate" title="Name">Lst anesdjsalk</div></th>
                    <th scope="col"><div class="slds-truncate" title="Type">lksdnasdkjds</div></th>
                </tr>
            
            </thead>
    <aura:iteration items="{!v.contacts}" var="cont">    
    <table>
            <tr>
                <td>
                    <force:inputField value="{!cont.LastName}"/>
                </td>
                <td>
                    <force:inputField value="{!cont.AccountId}"/>
                </td>
                <td>
                    <force:inputField value="{!cont.Email}"/>
                </td>
            </tr>
        </table>
    </aura:iteration>
    </table>
    <lightning:button type="submit" label="NDC Verify" class="slds-float--right">
    </lightning:button>
</aura:component>