浏览代码

Fixed existing selections not being respected with array data

This fixes an edge case that occurred pretty much whenever anyone would
use array data with existing selections along with a placeholder. This
caused the existing selections to be discarded, because the `selected`
property was not being transferred over to the new option. This was
based the new data was being preferred over the data that could be
inferred from the option, and the new data typically did not include the
selected state. As a result, the option was assumed to not be selected.

This was not cause by existing tests because all of the existing tests
only covered cases where the selected option was the first option, and
that was not affected by this bug.
Kevin Brown 9 年之前
父节点
当前提交
f3b9693ad9
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/js/select2/data/array.js

+ 1 - 1
src/js/select2/data/array.js

@@ -52,7 +52,7 @@ define([
         var $existingOption = $existing.filter(onlyItem(item));
 
         var existingData = this.item($existingOption);
-        var newData = $.extend(true, {}, existingData, item);
+        var newData = $.extend(true, {}, item, existingData);
 
         var $newOption = this.option(newData);