0

我有一个选择菜单,它是一个刺激目标。该选择的每个选项都有一个自定义数据属性。当该选择更改时,我需要刺激控制器从所选选项中读取数据集属性……而不是选择菜单目标。

在控制器动作中,event.currentTarget 是设置目标属性的选择菜单。相反,我希望它是选定的选项。

// this correctly returns the selected options value attribute.  Stimulus must know what you want in this case.
event.currentTarget.value



// However, calling this returns the classList for the target...which is the select, not the option.
event.currentTarget.classList



// And, calling this returns 'undefined' because data-value is not defined on the target select, it's defined on the selected option...which is not the currentTarget.
event.currentTarget.dataset.value

因此,当我在刺激控制器中调用 event.currentTarget.dataset.value 时,我实际上是在从所选选项中寻找 data-value='xxx' 。但是,刺激是在目标选择菜单上寻找数据值。

更改目标菜单时,如何从所选选项返回“xxx”数据值属性?

4

0 回答 0