【问题标题】:Custom attributes in ReactReact 中的自定义属性
【发布时间】:2016-09-22 17:20:33
【问题描述】:
【问题讨论】:
标签:
facebook
reactjs
polymer
web-component
【解决方案1】:
因为 React 设计为不向 html 属性传递任何数据,仅将数据存储在组件的 state 或 props 中。
【解决方案2】:
试试这个方法你可以在点击事件的控制台中看到属性值
//...
alertMessage (cEvent){
console.log(cEvent.target.getAttribute('customEvent')); /*display attribute value */
}
//...
在渲染方法中简单地添加 customAttribute 作为您的愿望
render(){
return <div>
//..
<button customAttribute="My Custom Event Message" onClick={this.alertMessage.bind(this) } >Click Me</button>
</div>
}
//...