From 5a1d6f2be49a59ff301ce8440277105fd03ad4c5 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 15 Jul 2019 08:07:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20longbow-select=20=E6=94=AF=E6=8C=81=20d?= =?UTF-8?q?ata-default-val=20=E9=BB=98=E8=AE=A4=E5=80=BC=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/lib/longbow-select/longbow-select.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Bootstrap.Admin/wwwroot/lib/longbow-select/longbow-select.js b/Bootstrap.Admin/wwwroot/lib/longbow-select/longbow-select.js index 313b19a8..88114688 100644 --- a/Bootstrap.Admin/wwwroot/lib/longbow-select/longbow-select.js +++ b/Bootstrap.Admin/wwwroot/lib/longbow-select/longbow-select.js @@ -76,11 +76,10 @@ } this.$input.attr('placeholder', this.options.placeholder); - // init dropdown-menu + // init dropdown-menu data var data = this.$element.find('option').map(function () { return { value: this.value, text: this.text, selected: this.selected } }); - this.reset(data); // bind attribute ["data-valid", "data-required-msg"].forEach(function (v, index) { @@ -126,6 +125,9 @@ if (that.$input[0] !== e.target) that.closeMenu(); }); + + // init dropdown-menu + this.reset(data); }; _proto.closeMenu = function () { @@ -155,8 +157,10 @@ $.each(value, function (index) { var $item = $('' + this.text + ''); that.$menus.append($item); - if (this.selected === true || this.value === oldValue || index === 0) { + 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'); } });