浏览代码

Unselect events: cache lookup key fix (#6179)

* During selection and unselection events, retrieve cached item data using the original 'option' element as the cache lookup key instead of the event target

* Fixup: only use 'option' element as cache lookup key during unselection -- not selection -- events

* Narrow down 'option' element query to find the unselected item by value

* Consistency: prefer jQuery.find...each pattern as used elsewhere in the codebase

* Lint fixup: fit within line length limits

* Use equality checks instead of jQuery/CSS selector attribute matching to filter relevant 'option' elements
James Addison 2 年之前
父节点
当前提交
d961613058
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/js/select2/data/select.js

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

@@ -114,7 +114,12 @@ define([
     });
 
     container.on('unselect', function (params) {
-      self.unselect(params.data);
+      container.$element.find('option').each(function () {
+        if ($(this).val() == params.data.id) {
+          var data = Utils.GetData(this, 'data');
+          self.unselect(data);
+        }
+      });
     });
   };