Last active
December 14, 2015 00:29
-
-
Save ypxu/4998881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use case sample | |
this.$(this.selectItemsTag).select2({ | |
placeholder:"Enter an items", | |
multiple:true, | |
minimumInputLength:1, | |
maximumSelectionSize:200, | |
initSelection : function (element, callback) { | |
var data = []; | |
var val = element.val() || ""; | |
_.each(val.split(","), function(item){ | |
data.push({id: item, text:item, label: item}); | |
}); | |
callback(data); | |
}, | |
}); | |
// code from select2 | |
// multi | |
setVal: function (val) { | |
var unique; | |
if (this.select) { | |
this.select.val(val); | |
} else { | |
unique = []; | |
// filter out duplicates | |
$(val).each(function () { | |
if (indexOf(this, unique) < 0) unique.push(this); | |
}); | |
this.opts.element.val(unique.length === 0 ? "" : unique.join(this.opts.separator)); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The performance issue on setVal function when you have large list of items. The de-duplicate process slow thing down.