简体   繁体   中英

How can I order the filter menu in alphabetical order

Hi i am using reactjs searchkit component in my project. As a requirement, I need to list the filter menu order by alphabetical order

In the below picture, I need to order Actors list in alphabetical order, how can i do this?

在此处输入图片说明

Can anybody know how to do this?

I have written the following code based on the assumption that that your RefinementFilterComponent is a stateless functional component.

Here is a link to dev docs related to lists and mapping. https://facebook.github.io/react/docs/lists-and-keys.html

const sortActors = props.title.sort((a, b) => {
  const [aFirst, aLast] = a.split(' ');
  const [bFirst, bLast] = b.split(' ');
    return aLast > bLast ? 1 : -1;
})

const renderActors = sortActors
  .map(actor => 
    <li key={actor.toString()}>
      {actor}
    </li>
  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM