Skip to content

Commit c7cccca

Browse files
committed
Fix #157
Bringing in lookup by key suggestion rather than building and searching an array.
1 parent 5f893aa commit c7cccca

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/jquery.multiselect.filter.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@
7373
this.update();
7474

7575
// gather an array of the values that actually changed
76-
var values = $inputs.map(function() {
77-
return this.value;
78-
}).get();
76+
var values = {};
77+
$inputs.each(function() {
78+
values[this.value] = true;
79+
});
7980

8081
// select option tags
8182
this.element.find('option').filter(function() {
82-
if(!this.disabled && $.inArray(this.value, values) > -1) {
83+
if(!this.disabled && values[this.value]) {
8384
_self._toggleState('selected', flag).call(this);
8485
}
8586
});

src/jquery.multiselect.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,16 @@
517517
this.update();
518518

519519
// gather an array of the values that actually changed
520-
var values = $inputs.map(function() {
521-
return this.value;
522-
}).get();
520+
var values = {};
521+
$inputs.each(function() {
522+
values[this.value] = true;
523+
});
523524

524525
// toggle state on original option tags
525526
this.element
526527
.find('option')
527528
.each(function() {
528-
if(!this.disabled && $.inArray(this.value, values) > -1) {
529+
if(!this.disabled && values[this.value]) {
529530
self._toggleState('selected', flag).call(this);
530531
}
531532
});
@@ -545,7 +546,7 @@
545546
if(flag) {
546547
// remember which elements this widget disabled (not pre-disabled)
547548
// elements, so that they can be restored if the widget is re-enabled.
548-
inputs = inputs.filter(':enabled').data(key, true)
549+
inputs = inputs.filter(':enabled').data(key, true);
549550
} else {
550551
inputs = inputs.filter(function() {
551552
return $.data(this, key) === true;

0 commit comments

Comments
 (0)