码迷,mamicode.com
首页 > Web开发 > 详细

React实践:自定义html特性不显示

时间:2017-09-04 20:19:11      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:bsp   use   href   title   can   link   reactjs   back   环境   

发现React中自定义的html特性在render后是不现实,而且getAttribute方法也只能获取到undefined。

后来去stackoverflow提问,网友回答说:

It depends on which attributes you are talking about. Usually, ReactJS components can handle most of the commons scenarios without the need of self defining attributes. – Hemerson Carlin 52 mins ago

也对,毕竟React本来就是构架UI的框架,似乎也没必要在html中绑定自定义属性,data都在组件内部,完全可以创建数据对象来存储信息。

不过也有另一个网友给出一种在渲染时给元素自定义标识的方法:

1       this.state.list.forEach(function(v,i,a){
2       let id = v.vid.toString();
3        let temp=<li  key={id} onClick={() => that.handle_del(id)}  > {v.thing}</li>;
4         todo.push(temp);
5       });

这里id其实利用了闭包,在调用组件的方法时,把当前环境下的id传过去。也还不错。

React实践:自定义html特性不显示

标签:bsp   use   href   title   can   link   reactjs   back   环境   

原文地址:http://www.cnblogs.com/alan2kat/p/7475362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!