Browse Source

Automatically create options on select

Kevin Brown 10 năm trước cách đây
mục cha
commit
07e82d6be8

+ 12 - 0
dist/js/select2.amd.full.js

@@ -1212,6 +1212,18 @@ define('select2/data/array',[
 
   Utils.Extend(ArrayAdapter, SelectAdapter);
 
+  ArrayAdapter.prototype.select = function (data) {
+    var $option = this.$element.find('option[value="' + data.id + '"]');
+
+    if ($option.length === 0) {
+      $option = this.option(data);
+
+      this.$element.append($option);
+    }
+
+    ArrayAdapter.__super__.select.call(this, data);
+  };
+
   ArrayAdapter.prototype.convertToOptions = function (data) {
     var self = this;
 

+ 12 - 0
dist/js/select2.amd.js

@@ -1212,6 +1212,18 @@ define('select2/data/array',[
 
   Utils.Extend(ArrayAdapter, SelectAdapter);
 
+  ArrayAdapter.prototype.select = function (data) {
+    var $option = this.$element.find('option[value="' + data.id + '"]');
+
+    if ($option.length === 0) {
+      $option = this.option(data);
+
+      this.$element.append($option);
+    }
+
+    ArrayAdapter.__super__.select.call(this, data);
+  };
+
   ArrayAdapter.prototype.convertToOptions = function (data) {
     var self = this;
 

+ 12 - 0
dist/js/select2.full.js

@@ -10747,6 +10747,18 @@ define('select2/data/array',[
 
   Utils.Extend(ArrayAdapter, SelectAdapter);
 
+  ArrayAdapter.prototype.select = function (data) {
+    var $option = this.$element.find('option[value="' + data.id + '"]');
+
+    if ($option.length === 0) {
+      $option = this.option(data);
+
+      this.$element.append($option);
+    }
+
+    ArrayAdapter.__super__.select.call(this, data);
+  };
+
   ArrayAdapter.prototype.convertToOptions = function (data) {
     var self = this;
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/js/select2.full.min.js


+ 12 - 0
dist/js/select2.js

@@ -1640,6 +1640,18 @@ define('select2/data/array',[
 
   Utils.Extend(ArrayAdapter, SelectAdapter);
 
+  ArrayAdapter.prototype.select = function (data) {
+    var $option = this.$element.find('option[value="' + data.id + '"]');
+
+    if ($option.length === 0) {
+      $option = this.option(data);
+
+      this.$element.append($option);
+    }
+
+    ArrayAdapter.__super__.select.call(this, data);
+  };
+
   ArrayAdapter.prototype.convertToOptions = function (data) {
     var self = this;
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/js/select2.min.js


+ 12 - 0
src/js/select2/data/array.js

@@ -13,6 +13,18 @@ define([
 
   Utils.Extend(ArrayAdapter, SelectAdapter);
 
+  ArrayAdapter.prototype.select = function (data) {
+    var $option = this.$element.find('option[value="' + data.id + '"]');
+
+    if ($option.length === 0) {
+      $option = this.option(data);
+
+      this.$element.append($option);
+    }
+
+    ArrayAdapter.__super__.select.call(this, data);
+  };
+
   ArrayAdapter.prototype.convertToOptions = function (data) {
     var self = this;
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác