Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
100 views
in Technique[技术] by (71.8m points)

javascript - How to determine valid selector for dynamic class (react)?

I have below div (which is a dropdown) in frontend, i am trying to get the selected value from "li" for exg "Price Highest" is selected then i am trying to get its value using javascript. enter image description here

<div class="makeStyles-sortOptionDesktopContainer-155">
<a class="makeStyles-selection-156">Price Highest</a>
<ul>
<li><a>Our Favs</a></li>
<li><a>Newest</a></li>
<li><a>Price Highest</a></li>
<li><a>Price Lowest</a></li>
</ul>
</div>

 <div className={classes.sortOptionDesktopContainer}>
    <a className={classes.selection}>{sortingOption[selectedIndex].text}</a>
    <ul>
        {
            sortingOption.map((item,index) => (<li key={`sort-opt-${index}`} onClick={()=>{setIndex(index);onUpdateSort(item.id)}}><a>{item.text}</a></li>))
        }
    </ul>   
</div>

<SortOptions selectedOption={pageData.sort} onUpdateSort={applySortOption}/>
  
const applySortOption = (sortOption) => {
        updateStore(store => ({
        reloading: true,
        pageData: {
            ...store.pageData,
            page:1,
            sortBy:sortOption
        },
        }))
        console.log(store.pageData)
        console.log(sortOption)
    }
        

The issue is it uses dynamic class name, i am not sure how to use this class name as selectors in javascript any thoughts on this ?

question from:https://stackoverflow.com/questions/65931638/how-to-determine-valid-selector-for-dynamic-class-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...