Компоненты salesforce Lightning просматривают данные, которые не обновляются

Я создал простой компонент для отображения контактной информации. Но это не отображается на странице. понятия не имею, что происходит?

Я проверил, что контроллер вершины правильно возвращает контакт. Но компонент не отрисовывается с полученным контактным объектом.

<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];
    }
}

person Nepz Solutions    schedule 03.07.2018    source источник


Ответы (1)


Я нашел ответ, мне нужно добавить в компонент атрибут Contact,

<aura:attribute name="contact" type="Contact"/>
person Nepz Solutions    schedule 04.07.2018