Select2获取html数据属性

时间:2017-03-17 04:50:18

标签: jquery jquery-select2

我正在使用最新的select2版本。

但坚持获得for row in tables append to html <tr><td>data</td><td>moredata</td></tr> insert html into <table></table> html属性。

<select>

我按照此解决方案How to get data attribute of <select> for use in select2 from inside .select2() ajax call?和此处https://github.com/select2/select2/issues/3361但仍然没有运气。

我的<select name="category" id="category-select" data-ajax--search="slug" class="select2 form-control m-b-2" multiple> </select> // SCRIPT const opts = { ajax: { url: "/menus/search", delay: 250, data: function (param) { return {q: param.term, page: param.page, category: $(this.element).data('search')}; }, processResults: ({data, total_count}, {page}) => { page = page || 1; return { results: data, pagination: { more: (page * 30) < total_count } }; }, cache: true }, scapeMarkup: markup => markup, templateResult: formatRepo, templateSelection: formatRepoSelection }; $('.select2').select2(opts); 始终data-ajax--search

任何解决方案?

1 个答案:

答案 0 :(得分:1)

尝试使用 $(this).data('ajax-Search')而不是$(this.element).data('search')