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

时间:2018-08-03 07:17:30

标签: javascript html-select

我有以下数组:

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

Choices.js默认情况下按字母顺序对其进行排序,并且OtherTMT结尾,这会给用户带来麻烦。

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

我尝试研究sortFilter函数,但它仅指定排序方法。

2 个答案:

答案 0 :(得分:2)

您似乎需要属性shouldSortreadme有详细信息。

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

答案 1 :(得分:0)

默认排序为true,但是您可以传递另一个属性shouldSort。

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