我的模态中有一个来自from的下拉菜单,我想按字母顺序排序。我尝试使用下面显示的功能来做到这一点,但是没有用。
模态表格
<div class="j-unit">
<label class="j-label">{{ trans("settings.traineesSupervisor") }}</label>
<select
name="trainees_supervisor_id_create"
id="trainees_supervisor_id_create"
class="form-control"
>
</select>
</div>
填写表格:
forms.getData("person/all", function(persons_data) {
persons_data = JSON.parse(persons_data);
persons_data.forEach(function(e) {
e.name = e.last_name + " " + e.first_name;
});
personList = persons_data;
forms.appendToSelect(
persons_data,
$("#trainees_supervisor_id_create"),
"person-id"
);
forms.appendToSelect(
persons_data,
$("#trainees_supervisor_id_update"),
"person-id"
);
});
我尝试排序:
var selectList = $("#trainees_supervisor_id_create select");
selectList.sort(function(a, b) {
a = a.name;
b = b.name;
return a - b;
});
$("#trainees_supervisor_id_create").html(selectList);