【问题标题】:Select2 + Django: set preferred list itemsSelect2 + Django:设置首选列表项
【发布时间】:2017-06-28 17:01:04
【问题描述】:

我使用 select2]1django-countries 以便为用户提供可能国家/地区的下拉列表。我现在想(1)拆分下拉列表或(2)重新排列项目/国家的顺序,即:

目前我得到一个按字母顺序排列的列表:

- select country
  - Afghanistan
  - Albania
  - Algeria
  ...
  - Kenya
  ...
  - Zimbabwe

我想要的是: (1)

- select country
  - Germany
  - Austria
  - Switzerland
  ---------------------------
  - Afghanistan
  - Albania
  - Algeria
  ...
  - Kenya
  ...
  - Zimbabwe

或 (2)

- select country
  - Germany
  - Austria
  - Switzerland
  - Afghanistan
  - Albania
  - Algeria
  ...
  - Kenya
  ...
  - Zimbabwe

这是我的 js:

$(document).ready(function () {
    $("#id_nationality").select2({
        default: 'Germany',
        placeholder: 'select country'
    });
});

我使用crispy-forms 进行表单渲染

【问题讨论】:

    标签: python django select2 django-countries


    【解决方案1】:

    已解决,因为 django-countries 已包含此功能。

    this

    【讨论】:

    • 嗨!您是否设法使用 COUNTRIES_FIRST _BREAK 并将 required 传递给选择元素来使用此选择?
    猜你喜欢
    • 2013-06-02
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 2014-10-10
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多