如何在ReactJS中检索选择选项数据属性值?

时间:2016-02-03 14:45:55

标签: reactjs

我一直在尝试从select选项中检索数据属性值的不同方法。我试过这些,但一切都是空的。任何帮助赞赏。

{"took":6,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.15342641,"hits":[{"_index":"prj1","_type":"mod","_id":"java2Ed","_score":0.15342641,"_source":{
"project_name": "Java 2 Edition"
}}]}}

1 个答案:

答案 0 :(得分:7)

您的代码无效,因为e.target正在返回整个选择字段而不是单个选项。您需要获取所选选项的索引,然后访问该自定义属性。在您的更改功能中,这将起作用:

event.target[event.target.selectedIndex].getAttribute('data-order')