Select2 formatResult获取选项的属性 [英] Select2 formatResult get attributes of option

查看:255
本文介绍了Select2 formatResult获取选项的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用< select>

我们需要以上链接中指定的相同内容.但是,如何获取formatResult函数中option元素的属性?

We need the same thing specified in the above link. But, how to get the attributes of option element in formatResult function?

推荐答案

您可以尝试以下代码:

  $select2.data('placeholder', 'please choose').html(_options).select2({
                    formatNoMatches: function (term) {
                        return 'There is no "' + term + '" item';
                    },
                    formatResult: function(term) {
                        return $(term.element).data('cnt');
                    },
                    allowClear: true
  });

JSBIN

这篇关于Select2 formatResult获取选项的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆