Я использую плагин Bootstrap Dual Listbox и настроил на своем сайте bootstrap dual listbox. Я хочу добавить атрибут data-sortIndex вручную к элементам, которые я добавляю кодом jquery. Я попытался получить доступ к свойству sortIndex объекта bootStrapDualListbox, но оно не работает.
$(document).ready(function(){
var listBox = $("select[name='duallist']").bootstrapDualListbox({
nonSelectedListLabel:'Non-Selected',
selectedListLabel:'Selected',
filterPlaceHolder:'Search',
moveAllLabel:'Move All'
});
$("select[name='duallist_helper1']").on('change',function(e){
$("select[name='duallist'] option:selected").each(function(index,item){
if($(item).val() == "OT"){
$(item).prop('selected',false);
$(item).removeAttr('data-sortIndex');
var otherValue = prompt("Other","");
if(otherValue != null || otherValue != '' ){
var newOption = document.createElement("option");
newOption.value = otherValue;
newOption.selected = true;
newOption.setAttribute('data-sortIndex',listBox.sortIndex);
newOption.appendChild(document.createTextNode(otherValue));
listBox.append(newOption);
}
listBox.bootstrapDualListbox('refresh');
}
});
});
listBox.sortIndex возвращает неопределенное значение. Github-страница плагина, содержащая код - https://github.com/istvan-ujjmeszaros/bootstrap-duallistbox/blob/v4/src/jquery.bootstrap-duallistbox.js