【问题标题】:salesforce lightning components view data not getting refreshedSalesforce Lightning 组件视图数据未刷新
【发布时间】:2018-07-03 20:58:33
【问题描述】:

我已经构建了一个简单的组件来显示联系信息。但是,它没有显示在页面中。不知道发生了什么?

我已检查 apex 控制器是否正确返回联系。但是,该组件没有使用接收到的联系人对象进行渲染。

<aura:application >
    <aura:attribute name="contactId" type="String"/>

    <c:PreferenceComponent contactId="{!v.contactId}"/>
</aura:application>

<aura:component controller="PreferenceComponentCtrlr">
    <aura:attribute name="contactId" type="String"/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <lightning:card variant="Narrow" title="{!v.contact.Name}" 
                    iconName="standard:contact">
        <p class="slds-p-horizontal_small">
            {!v.contact.Phone}
        </p>
        <p class="slds-p-horizontal_small">
            {!v.contact.MailingStreet}
        </p>
    </lightning:card>    
</aura:component>

({
    doInit : function(component, event, helper) {
        var action = component.get("c.getContact");
        action.setParams({
            contactId : component.get("v.contactId")
        });

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === 'SUCCESS'){
                component.set("v.contact", response.getReturnValue());
            }
        });

        $A.enqueueAction(action);                           
    }
})

public class PreferenceComponentCtrlr {

    @AuraEnabled
    public static Contact getContact(Id contactId) {
        System.debug('contactId - ' + contactId);
        return [Select Id, Name, Phone, MailingStreet From Contact Where Id =: contactId LIMIT 1];
    }
}

【问题讨论】:

    标签: salesforce lightning


    【解决方案1】:

    我找到了答案,我需要给组件添加Contact属性,

    <aura:attribute name="contact" type="Contact"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 2019-07-14
      • 1970-01-01
      相关资源
      最近更新 更多