I have been trying to set background-image to divs inside Template iteration in LWC component. But when I am trying to locate divs using this.template.queryLocatorAll, I am not getting any Divs. Is it because they are inside Template iteration. If so then how can iI locate these elements and set background images to these divs?
Here is my HTML code:
<div class="slideshow-container">
<template for:each=each="{result}" for:item="res">
<div class="mySlides fade" key=key="{res.id} >">
<div data-id= id="{res.Id} " class="slds-box slds-box_x-small slds-text-align_center slds-m-around_x-small">
<div>
<div >
{res.Id}
{res.Comments__c}
</div>
</div>
</div>
</div>
</template>
</div>
and here is my JS code:
const divs = this.template.querySelectorAll('div');
for (var i = for(var0; i=0;i<thisi < this.result.length;i++length; i++) {
const target = this.template.querySelectorAll('[data-id='+thisid=' + this.result[i].id+']'id + ']');
console.log('target'+target'target' + target.length);
}
if (divs) {
console.log('divs'+divs'divs' + divs.length);
for (var i = 0; i for(var< i=0;i<divsdivs.length;i++length; i++) {
this.result.map((res) => {
const div = Object.values(divs).filter(res => (res.getAttribute('data-id') === res.Id))[i];
div.style.backgroundImage = 'url()';
});
}
}
Any help will be appericatedappreciated.