代码之家  ›  专栏  ›  技术社区  ›  Bargain23

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

  •  0
  • Bargain23  · 技术社区  · 7 年前

    我有以下数组:

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

    Choices.js 默认情况下按字母顺序排序,并且 Other 在之前结束 TMT 这对用户来说是刺耳的。

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

    我试着调查 sortFilter 函数,但它只指定排序方法。

    2 回复  |  直到 7 年前
        1
  •  2
  •   OliverRadini    7 年前

    看来你需要那房子 shouldSort . 这个 readme 有细节。

    const $projectDropdown = new Choices($this[0], {
      placeholder: true,
      placeholderValue: 'Select a project'
      shouldSort: false,
    })
    
        2
  •  0
  •   Sookie Singh    7 年前

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

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