选择选项在添加新选项时消失 [英] Select options disappearing when appending new option
问题描述
我当前正在创建一个界面,以双击双击一个选择元素中的一个选项,并将其附加到另一个选择元素中.
I'm currently creating a interface to select an option from one select element on double click, and append it to another select element.
我遇到的问题是这样做的时候,它已经添加并可见,但是所有其他选项在目标选择中都消失了,直到我单击该选项然后单击关闭.
The issue I am coming across is when doing so, it is added and visible, however all other options disappear in the destination select, until I click on the option and then click off.
您可以在此处看到以下操作: https://i.imgur.com/jSXoIAi.gifv
You can see this in action here: https://i.imgur.com/jSXoIAi.gifv
我当前的实现如下:
$('body').on('dblclick', '#availableColumnsSelect > option', function (e) {
var option = $(this);
//Add option to destination
displayColumnsSelect.append($('<option>', { value: option.val(), text: option.val() }));
//Remove option from source
option.remove();
//Sort the select options
sortSelect("#displayColumnsSelect");
var optionsAvailable = $("#availableColumnsSelect > option:not([disabled])").length;
if (optionsAvailable == 0) {
$("#noSelectedText").removeClass('hidden');
}
$("#noSelectedText").addClass('hidden');
});
底层HTML正按照其应有的方式构建.
The underlying HTML is being constructed exactly how it should.
有什么想法吗?
推荐答案
如前所述,问题出在sortSelection函数上.我不太清楚为什么,但是无论我实际上不再需要此功能.
As pointed out the issue was with the sortSelection function. I'm not quite sure why, but regardless I don't actually require this function anymore.
删除所述功能已解决了问题:)
Removing said function has resolved the issue :)
这篇关于选择选项在添加新选项时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!