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

Bar*_*n23 1 javascript html-select

我有以下数组:

options = [
  "Asset Management & Investment Funds",
  "Financial Institutions",
  "Life Sciences",
  "TMT",
  "Other"
]
Run Code Online (Sandbox Code Playgroud)

Choices.js默认按字母顺序排序,Other最后排在前面TMT这对用户来说是刺耳的。

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

我尝试查看该sortFilter函数,但它仅指定了排序方法。

Oli*_*ini 5

看起来您需要该属性shouldSort。该自述有更多的细节。

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