Select2: Data attributes on ajax call

Created on 20 Nov 2015  路  1Comment  路  Source: select2/select2

Hi,
I try to add a data-attribute on my option tag on a ajax call but I can't.

    processResults: function (data) { 
       return {
          results: $.map(data, function (item) {
                return {
                    text: item.text,
                    'data-tag': item.anotherValue,
                    id: item.id
                };
            })
        };
      },

>All comments

If you're dealing with AJAX, you have full control over the data objects. So you don't need to include data- in front of things, the names will be included just like id and text normally are.


This appears to be more of a usage question than a bug report or common feature request. As we continue to keep the Select2 issue tracker geared towards these two areas, bug reports and common feature requests, we are redirecting usage questions to other communities such as the mailing list, IRC, or Stack Overflow.

Was this page helpful?
0 / 5 - 0 ratings