반응형
controller에서 해당 레코드의 필드 값들을 가져올 수 있는 방법
<aura:component implements="force:hasRecordId,flexipage:availableForRecordHome">
<aura:attribute name="record" type="Object"/>
<aura:attribute name="fields" type="Object"/>
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="fieldData"
recordId="{!v.recordId}"
layoutType="FULL"
mode="VIEW"
fields="CenterId__r.Director__c"
targetRecord="{!v.record}"
targetFields="{!v.fields}"
recordUpdated="{!c.recordUpdate}"
targetError="{!v.recordLoadError}"
/>
<div>
<lightning:card iconName="standard:account" title="{!v.fields.Name}" >
<div class="slds-p-horizontal--small">
<p class="slds-text-heading--medium"><lightning:formattedPhone title="Phone" value="{!v.fields.Phone}" /></p>
<p class="slds-truncate"><lightning:formattedText title="Description" value="{!v.fields.Description}" /></p>
<p class="slds-truncate"> <lightning:formattedText title="Industry" value="{!v.fields.Industry}" /></p>
</div>
</lightning:card>
</div>
</aura:component>
문서에 의하면
Events
recordUpdated
The event fired when the record is loaded, updated, or deleted.
The recordUpdated event returns the following parameters.
따라서 로드될 때 필드의 정보들을 가져올 수 있다. 하지만 비동기 식으로 처리하기 때문에 init handler에서는 불러 올 수 없으므로 따로 함수를 만들어주어야 한다.
Controller
recordUpdate: function(component, event, helper) {
let recordObj = component.get("v.fields");
component.set("v.recordObj",recordObj);
}
부모의 필드 가져오는 방법
부모의 필드는 따로 fields = "test__r.Name" 이렇게 적어주어야 한다.
fields는 사용할 필드를 적어주는 것인데, 해당 개체의 레코드는 가져올 수 있는 이유가 targetFields를 사용하였기 때문이다.
차이를 알아보자.
targetRecord is the provided record. This attribute will contain only the fields relevant to the requested layoutType and/or fields atributes.targetFields is a simplified view of the fields in targetRecord, to reference record fields in component markup.
: targetRecord는 제공된 레코드입니다. 이 속성에는 요청된 layoutType 및/또는 필드 속성과 관련된 필드만 포함됩니다.
targetFields는 구성 요소 마크업의 레코드 필드를 참조하기 위해 targetRecord의 필드를 단순화한 보기입니다.
targetFields는 simpleRecord에 해당하는 속성입니다. targetFields는 targetRecord에 비해 사용하기 쉽습니다. 둘 다 사용할 필요는 없고 하나만 사용하면 됩니다.
반응형