【问题标题】:How to display page object field values in Lightning Component?如何在 Lightning 组件中显示页面对象字段值?
【发布时间】: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;
    }
}

【问题讨论】:

    标签: salesforce-lightning


    【解决方案1】:

    在 js 控制器中尝试从该行中删除引号:

    action.setParams({
            "PosId": recordId
        });
    

    所以它看起来像这样:

    action.setParams({ PosId: recordId });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      • 2022-07-27
      • 2013-09-27
      • 2017-09-30
      • 2020-07-16
      • 2015-06-08
      相关资源
      最近更新 更多