简体   繁体   English

如何按字母顺序排列过滤器菜单

[英]How can I order the filter menu in alphabetical order

Hi i am using reactjs searchkit component in my project. 嗨,我在我的项目中使用reactjs searchkit组件。 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. 我基于您的RefinementFilterComponent是无状态功能组件的假设编写了以下代码。

Here is a link to dev docs related to lists and mapping. 这是与列表和映射有关的开发文档的链接。 https://facebook.github.io/react/docs/lists-and-keys.html 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>
  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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