fix: 修复下拉框出现多个active选项问题

This commit is contained in:
Argo Zhang 2019-08-20 12:53:04 +08:00
parent cbf019131b
commit 66860ba873
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 3 additions and 1 deletions

View File

@ -149,15 +149,17 @@
// see https://gitee.com/LongbowEnterprise/longbow-select/issues/IZ3BR?from=project-issue
this.$input.attr('value', '').removeClass('is-valid is-invalid');
this.$menus.html('');
var $activeItem = null;
$.each(value, function (index) {
var $item = $('<a class="dropdown-item" href="#" data-val="' + this.value + '">' + this.text + '</a>');
that.$menus.append($item);
if (this.selected === true || this.value === oldValue || index === 0 || this.value === that.$element.attr('data-default-val')) {
that.$input.attr('value', this.text);
that.$element.val(this.value).attr('data-text', this.text);
$item.addClass('active');
$activeItem = $item;
}
});
if ($activeItem !== null) $activeItem.addClass('active');
this.source = value;
};