When upgrading to select2 4.0.3 on NuGet, I came cross a problem where selected items all say “[object Object]”. I traced the problem down to this method: https://github.com/select2/select2/blob/master/src/js/select2/data/select.js#L246. It appears that you are checking if the passed-in data is an empty object, and if it is not, you re-assign it with a new one with id
and text
populated with the passed in data. Then, text
and id
are assigned as:
if (item.id != null) {
item.id = item.id.toString();
}
I think the solution is to not name the item
you are initializing with the item
passed in as a parameter, so the data isn’t overwritten. Then, it should just work. I’m prepared to submit a pull-request for this, should you want it.