Salesforce LWC nested for each loops with if condition

342 Views Asked by At

I am trying to implement a listbox in LWC. The list box is showing values from a picklist in Account object. On click the value of the selected item is adding to an array. But on the UI it is not showing which objects are selected. I want to compare two arrays and if the value is found in selected array the rendering should have a slds-focus class applied to the item else it should not. How can I compare the values in the selected array with picklist values array. I was trying the following code but its not working.

<template for:each={picklistvalues} for:item="item" >
     <template key={item} for:each={selectedSource} for:item="sitem" >
          <div if:true={item = sitem}>
              <li role="presentation" class="slds-listbox__item" >
                 <div class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small" role="option">
                     <span class="slds-media__figure slds-listbox__option-icon"></span>
                        <span class="slds-media__body">
                            <span id={item} title={item} onclick={handleSelect}>{item}</span>
                                            </span>
                                            </div>
                                        </li>
                                    </div></template>
0

There are 0 best solutions below