salesforce lightning组件视图数据未刷新

salesforce lightning组件视图数据未刷新,salesforce,lightning,Salesforce,Lightning,我构建了一个简单的组件来显示联系人信息。但是,它没有显示在页面中。不知道发生了什么事 我已检查apex控制器是否正确返回触点。但是,该组件没有使用接收到的联系人对象进行渲染 <aura:application > <aura:attribute name="contactId" type="String"/> <c:PreferenceComponent contactId="{!v.contactId}"/> </aura:appli

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

我已检查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];
    }
}

{!v.contact.Phone}

{!v.contact.MailingStreet}

({ doInit:函数(组件、事件、助手){ var action=component.get(“c.getContact”); action.setParams({ contactId:component.get(“v.contactId”) }); action.setCallback(此,函数(响应){ var state=response.getState(); 如果(状态=='SUCCESS'){ set(“v.contact”,response.getReturnValue()); } }); $A.排队行动(行动); } }) 公共类首选项组件CtrlR{ @可听的 公共静态联系人getContact(Id contactId){ 系统调试('contactId-'+contactId); return[从联系人中选择Id、姓名、电话、邮件列表,其中Id=:contactId LIMIT 1]; } }
我找到了答案,我需要向组件添加Contact属性

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