Я пытаюсь создать простой компонент молнии, который будет отображать значения полей из объекта, на который он ссылается, на странице. Я применил учебник, но не могу получить значения полей для отображения на странице.
Мне не ясно, как ссылаться на идентификатор объекта на странице и / или нужно ли это для апекса. запрос или если значение поля может быть отображено без него.
Позиция __ 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;
}
}