ArrayEditable: replace self.$items

When shrinking the number of items, this allows the old elements to be
GCed sooner.
This commit is contained in:
Will Thompson 2016-05-04 11:17:56 +01:00 committed by j
parent 84b3c34130
commit adbf2dad81

View file

@ -142,23 +142,23 @@ Ox.ArrayEditable = function(options, self) {
} }
that.empty(); that.empty();
if (self.options.items.length == 0) { if (self.options.items.length == 0) {
self.$items[0] = Ox.Editable({ self.$items = [Ox.Editable({
editable: false, editable: false,
placeholder: self.options.placeholder, placeholder: self.options.placeholder,
type: self.options.type, type: self.options.type,
value: '' value: ''
}) })
.appendTo(that); .appendTo(that)];
} else { } else {
sortItems(); sortItems();
self.options.items.forEach(function(item, i) { self.$items = self.options.items.map(function appendItem(item, i) {
if (i && self.options.type == 'input') { if (i && self.options.type == 'input') {
$('<span>') $('<span>')
.addClass('OxSeparator') .addClass('OxSeparator')
.html(self.options.separator + ' ') .html(self.options.separator + ' ')
.appendTo(that); .appendTo(that);
} }
self.$items[i] = Ox.Editable({ return Ox.Editable({
autocomplete: self.options.autocomplete, autocomplete: self.options.autocomplete,
autocompleteReplace: self.options.autocompleteReplace, autocompleteReplace: self.options.autocompleteReplace,
autocompleteReplaceCorrect: self.options.autocompleteReplaceCorrect, autocompleteReplaceCorrect: self.options.autocompleteReplaceCorrect,