Can't get the target attributes of material-ui select react component

前端 未结 3 1692
暗喜
暗喜 2021-01-11 16:55

I\'m trying to get the id,name, and value from Select field element of Material-UI react component.

This is my container:

//some code is removed to k         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-11 17:45

    I'd keep it simpler using event.currentTarget instead of event.target. In your event handler, you can access the attribute of interest from the element that triggered the event by:

    _onChange(evt) {
        console.log(evt.currentTarget.getAttribute("data-name");
        console.log(evt.currentTarget.getAttribute("data-value");
    }
    

    thus calling .getAttribute on the attribute name prepended by "data-"

提交回复
热议问题