语义 UI 下拉选项数据属性 [英] Semantic UI Dropdown Option Data Attribute

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

问题描述

我一直试图在语义 UI 下拉列表 option 中附加一个 data-* 属性,但没有成功(数据属性没有被复制到结果下拉选项).

I've been trying to attach a data-* attribute in a Semantic UI dropdown option but to no success (the data attributes are not being copied to the resulting dropdown options).

这是我的select的结构:

<select id='my-dropdown' name='department'>
    <option value='1' data-wsg='something'>Department 1</option>
    <option value='2' data-wsg='another'>Department 2</option>
    . . .
    <option value='n' data-wsg='custom data'>Department N</option>
</select>

jQuery

$("#my-dropdown").dropdown({
    allowAdditions: false,
    fullTextSearch: true,
    onHide: function() {
        // Some codes.
    },
    onChange: function(value, text, choice) {
        // Access the data-wsg attribute of the selected option.
    }
});

我已经阅读了一些,但我所看到的关于数据属性支持的所有内容都是将设置存储在那里.不是我真正需要的.

I've been reading around a bit but all I saw regarding data attribute support was storing the settings in there. Not really what I need.

希望有人做过类似的事情并告诉我解决方案是什么.

Hopefully someone has done something similar and let me know what the solution is.

推荐答案

它并不漂亮,但您可以使用 onChange 中的详细信息来查找数据属性.您所追求的功能在这里被明确拒绝 - https://github.com/Semantic-Org/Semantic-UI/issues/931

Its not pretty, but you can use the details in the onChange to hunt down the data attribute. The functionality you are after was specifically rejected here - https://github.com/Semantic-Org/Semantic-UI/issues/931

onChange: function(value, text, choice) {
    $(this).children('option[value=' + $(choice).data('value') + ']').data('wsg')
}

这篇关于语义 UI 下拉选项数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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