فهرست منبع

Speed up calls to get the currently selected options (#5775)

* JQuery "find" replaced with more efficient "querySelectorAll"

* Refactored to use Array.prototype.map

Co-authored-by: Kevin Brown <[email protected]>
Anton Dyshkant 5 سال پیش
والد
کامیت
cbadb0a409
1فایلهای تغییر یافته به همراه6 افزوده شده و 8 حذف شده
  1. 6 8
      src/js/select2/data/select.js

+ 6 - 8
src/js/select2/data/select.js

@@ -13,16 +13,14 @@ define([
   Utils.Extend(SelectAdapter, BaseAdapter);
 
   SelectAdapter.prototype.current = function (callback) {
-    var data = [];
     var self = this;
 
-    this.$element.find(':selected').each(function () {
-      var $option = $(this);
-
-      var option = self.item($option);
-
-      data.push(option);
-    });
+    var data = Array.prototype.map.call(
+      this.$element[0].querySelectorAll(':checked'),
+      function (selectedElement) {
+        return self.item($(selectedElement));
+      }
+    );
 
     callback(data);
   };