React is able to render custom attributes as described at http://facebook.github.io/react/docs/jsx-gotchas.html :
(React能够呈现自定义属性,如http://facebook.github.io/react/docs/jsx-gotchas.html中所述 :)
If you want to use a custom attribute, you should prefix it with data-.
(如果要使用自定义属性,则应在其前面加上data-。)
<div data-custom-attribute="foo" />
And that's great news except I can't find a way to access it from the event object eg:
(这是个好消息,除了我找不到从事件对象访问它的方法,例如:)
render: function() {
...
<a data-tag={i} style={showStyle} onClick={this.removeTag}></a>
...
removeTag: function(event) {
this.setState({inputVal: event.target????});
},
The element and data-
property render in html fine.
(元素和data-
属性以html格式呈现。)
Standard properties like style
can be accessed as event.target.style
fine.(像style
这样的标准属性可以作为event.target.style
访问。)
Instead of event.target
I tried:(我试过而不是event.target
:)
event.target.props.data.tag
event.target.props.data["tag"]
event.target.props["data-tag"]
event.target.data.tag
event.target.data["tag"]
event.target["data-tag"]
none of these worked.
(这些都没有奏效。)
ask by andriy_sof translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…