【发布时间】:2020-02-11 19:21:36
【问题描述】:
我正在尝试构建一个简单的闪电组件,该组件将显示它在页面上引用的对象的字段值。我已应用教程,但无法获取要在页面上显示的字段值。
我不清楚如何引用页面上对象的 id 和/或是否需要顶点查询,或者是否可以在没有它的情况下呈现字段值。
Position__c 是具有一些字段的引用对象 API: 这是我的组件:
<aura:component implements="flexipage:availableForAllPageTypes" controller="positionController" access="global">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="position" type="Position__c"/>
{!v.position.Job_Posting_One_liner__c} //I really just need to print this field value
</aura:component>
控制器:
({
doInit : function(component, event, helper) {
var recordId = component.get("v.recordId");
var action = component.get("c.getPositionDetails");
action.setParams({
"PosId": recordId
});
action.setCallback(this, function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
var position = response.getReturnValue();
component.set("v.position", position);
}
});
$A.enqueueAction(action);
}
顶点:
public class positionController {
@AuraEnabled
public static Position__c getPositionDetails(Id PosId) {
Position__c positions =
[SELECT Id, Job_Posting_One_liner__c FROM Position__c Where Id= :PosId limit 1 ];
return positions;
}
}
【问题讨论】: