TransWikia.com

lightning:carousel error

Salesforce Asked by Sankhadeep Biswas on November 3, 2020

I’m new to lightning and never used carousel component. My requirement is to display different images by querying from object level and upon clicking on the picture it will call another component and pass a value which will be used as an attribute of the 2nd component.Kindly help.. please find below component ..

apex

public class imagecheckcontact{

@AuraEnabled 
public static List<contact> getcons(){
    return [Select Id,name,sankha__image__c from contact where id in ('00328000014LZcM', '00328000014LZjA')];
}

}

component

<lightning:carousel >
    <aura:iteration items="{!v.conct}" var="con">
        <lightning:carouselImage width="500px" height="600px" src = "{!con.sankha__image__c}" 
                                 description = "First card description."  onclick="{c.navigate}"  header = "{!con.name}" 
                                 >
        </lightning:carouselImage>
    </aura:iteration>
</lightning:carousel>

JS


({
    doInit : function(component, event, helper) {
        var action = component.get("c.getcons"); 
        action.setCallback(this, function(response){
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                var retrunRes = response.getReturnValue();
                component.set("v.conct" ,retrunRes );
            }
        });
        $A.enqueueAction(action);
    },
    navigate:function(component, event, helper) {
            var evt = $A.get("e.force:navigateToComponent");
        evt.setParams({
            componentDef : "c:Helloworld",
            componentAttributes: {
                contactName : component.get("v.contact.Name")
            }
        });
        evt.fire();
    }

})

One Answer

You can not display images in carousel which are type of Rich text area. You have to break the image URL to required format and pass to src tag in lightning carousel.

src tag in lighting carousal accepts only this format /sfsites/c/servlet/rtaImage?eid=a0B9E000004VP64&feoid=00N9E0000055I7z&refid=0EM9E000000HpxY

find below example how can you break URL to required format from apex send it in this format.

NOte: Even I am trying to capture ID from onclick of image. but no sucess please help me

Seminar_Catalog__c camp = [SELECT Id, Image__c FROM Seminar_Catalog__c where id ='a079E00000ALyU1' LIMIT 1];
System.debug('Rich field:');
System.debug(camp.Image__c);
String firstSubString = camp.Image__c.substringBetween('<img', 'img>');
System.debug('First substring: ' + firstSubString);
String secondSubString = firstSubString.substringBetween('src="', '"');
System.debug('Second substring: ' + secondSubString);
String link = secondSubString.replace('amp;', '');
System.debug('Link: ' + link); 

Answered by Rajesh P on November 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP