简体   繁体   English

如何在Choices.js中禁用按字母顺序对项目的自动排序?

[英]How to disable the automatic sorting of items alphabetically in Choices.js?

I have the following array: 我有以下数组:

options = [
  "Asset Management & Investment Funds",
  "Financial Institutions",
  "Life Sciences",
  "TMT",
  "Other"
]

Choices.js by default sorts it alphabetically, and Other ends up before TMT which is jarring for the user. 默认情况下, Choices.js按字母顺序对其进行排序,而“ OtherTMT之前出现,这对用户不利

const $projectDropdown = new Choices($this[0], {
  placeholder: true,
  placeholderValue: 'Select a project'
})

I tried look into the sortFilter function, but it only specifies the method of sorting. 我尝试查看sortFilter函数,但它仅指定排序方法。

It looks like you need the property shouldSort . 看来您需要属性shouldSort The readme has details. 自述文件有详细信息。

const $projectDropdown = new Choices($this[0], {
  placeholder: true,
  placeholderValue: 'Select a project'
  shouldSort: false,
})

Default sorting is true but you can pass another property shouldSort. 默认排序为true,但您可以传递另一个属性shouldSort。

const $projectDropdown = new Choices($this[0], {
  placeholder: true,
  placeholderValue: 'Select a project',
  shouldSort: false
})

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

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