Here we taking a simple example to see how to use force:recordData to view the record.
Put the below component in account record detail page.
viewcomp.cmp
<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" access="global" >
<aura:attribute name="record" type="Object"/>
<aura:attribute name="recordFieldsToQuery" type="Object"/>
<aura:attribute name="recordError" type="String"/>
<force:recordData aura:id="savingRecord"
recordId="{!v.recordId}"
layoutType="FULL"
mode="VIEW"
targetRecord="{!v.record}"
targetFields="{!v.recordFieldsToQuery}"
targetError="{!v.recordError}"
/>
<!--We are using lightning card to display fields of account object-->
<lightning:card iconName="action:preview" title="View Account">
<div class="slds-p-horizontal--small">
<lightning:formattedText title="Account name" value="{!v.recordFieldsToQuery.Name}"/>
<br/>
<lightning:formattedText title="Account billing city" value="{!v.recordFieldsToQuery.BillingCity}" />
</div>
</lightning:card>
</aura:component>
Put the above component on account record detail page.
OUTPUT:
Put the below component in account record detail page.
viewcomp.cmp
<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" access="global" >
<aura:attribute name="record" type="Object"/>
<aura:attribute name="recordFieldsToQuery" type="Object"/>
<aura:attribute name="recordError" type="String"/>
<force:recordData aura:id="savingRecord"
recordId="{!v.recordId}"
layoutType="FULL"
mode="VIEW"
targetRecord="{!v.record}"
targetFields="{!v.recordFieldsToQuery}"
targetError="{!v.recordError}"
/>
<!--We are using lightning card to display fields of account object-->
<lightning:card iconName="action:preview" title="View Account">
<div class="slds-p-horizontal--small">
<lightning:formattedText title="Account name" value="{!v.recordFieldsToQuery.Name}"/>
<br/>
<lightning:formattedText title="Account billing city" value="{!v.recordFieldsToQuery.BillingCity}" />
</div>
</lightning:card>
</aura:component>
Put the above component on account record detail page.
OUTPUT:
No comments:
Post a Comment