瀏覽代碼

Normalize ids to string for remote data

This also fixes an issue where we were using the `full_name` for
the value instead of the `id` in the example, which technically
wasn't correct.

This closes https://github.com/select2/select2/issues/3148.
Kevin Brown 10 年之前
父節點
當前提交
a06379ce8d
共有 6 個文件被更改,包括 14 次插入5 次删除
  1. 4 1
      dist/js/select2.full.js
  2. 0 0
      dist/js/select2.full.min.js
  3. 4 1
      dist/js/select2.js
  4. 0 0
      dist/js/select2.min.js
  5. 2 2
      docs/examples.html
  6. 4 1
      src/js/select2/results.js

+ 4 - 1
dist/js/select2.full.js

@@ -825,7 +825,10 @@ S2.define('select2/results',[
 
         var item = $.data(this, 'data');
 
-        if ($.inArray(item.id, selectedIds) > -1) {
+        // id needs to be converted to a string when comparing
+        var id = '' + item.id;
+
+        if ($.inArray(id, selectedIds) > -1) {
           $option.attr('aria-selected', 'true');
         } else {
           $option.attr('aria-selected', 'false');

文件差異過大導致無法顯示
+ 0 - 0
dist/js/select2.full.min.js


+ 4 - 1
dist/js/select2.js

@@ -825,7 +825,10 @@ S2.define('select2/results',[
 
         var item = $.data(this, 'data');
 
-        if ($.inArray(item.id, selectedIds) > -1) {
+        // id needs to be converted to a string when comparing
+        var id = '' + item.id;
+
+        if ($.inArray(id, selectedIds) > -1) {
           $option.attr('aria-selected', 'true');
         } else {
           $option.attr('aria-selected', 'false');

文件差異過大導致無法顯示
+ 0 - 0
dist/js/select2.min.js


+ 2 - 2
docs/examples.html

@@ -231,7 +231,7 @@ $(".js-example-data-array-selected").select2({
 
       <p>
         <select class="js-example-data-ajax form-control">
-          <option value="select2/select2" selected="selected">select2/select2</option>
+          <option value="3620194" selected="selected">select2/select2</option>
         </select>
       </p>
 
@@ -291,7 +291,7 @@ $(".js-data-example-ajax").select2({
 
 <script type="text/x-example-code" class="js-code-data-ajax-html">
 <select class="js-data-example-ajax">
-  <option value="select2/select2" selected="selected">select2/select2</option>
+  <option value="3620194" selected="selected">select2/select2</option>
 </select>
 </script>
     </div>

+ 4 - 1
src/js/select2/results.js

@@ -106,7 +106,10 @@ define([
 
         var item = $.data(this, 'data');
 
-        if ($.inArray(item.id, selectedIds) > -1) {
+        // id needs to be converted to a string when comparing
+        var id = '' + item.id;
+
+        if ($.inArray(id, selectedIds) > -1) {
           $option.attr('aria-selected', 'true');
         } else {
           $option.attr('aria-selected', 'false');

部分文件因文件數量過多而無法顯示