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 ..
public class imagecheckcontact{
@AuraEnabled
public static List<contact> getcons(){
return [Select Id,name,sankha__image__c from contact where id in ('00328000014LZcM', '00328000014LZjA')];
}
}
<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();
}
})
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
1 Asked on January 29, 2021 by j-0
2 Asked on January 28, 2021 by samdev
excel javascript lightning lightning aura components lightning experience
1 Asked on January 28, 2021 by user87438
1 Asked on January 28, 2021 by javanoob
1 Asked on January 27, 2021 by shira-freed
1 Asked on January 27, 2021 by shobhit-saxena
0 Asked on January 26, 2021 by ifabiodlc
1 Asked on January 26, 2021 by dearbrother
2 Asked on January 26, 2021 by sitansu-pradhan
1 Asked on January 25, 2021 by user2957592
4 Asked on January 25, 2021 by kd7iwp
1 Asked on January 25, 2021 by valarie-simmons
0 Asked on January 24, 2021 by khushi
1 Asked on January 24, 2021 by walker
2 Asked on January 24, 2021 by zufra
0 Asked on January 23, 2021 by hermann-our
1 Asked on January 23, 2021 by alex-xiong
lightning design system lightning experience lightning web components popover slds
1 Asked on January 21, 2021 by mauforsalesforce
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP