2017-02-10 125 views
0

我使用select2] 1django-countries为了给用户下拉可能的国家。我现在想:(1)分裂下拉或(2)重新排列物品/国家的顺序,即:Select2 + Django:设置首选列表项目

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

- 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' 
    }); 
}); 

我用脆皮表格的形式呈现

回答

0

解决它,因为Django的国家包括了此功能。

请参阅this

+0

嗨!您是否设法使用COUNTRIES_FIRST _BREAK使用此选择并将'required'传递给select元素? –