我正在尝试为每个react元素添加元素id,但我无法将元素id添加到
React.createElement(
{
option:{this.state}
className:'form-control'
value:'sample'
}
)
发布于 2018-03-19 09:21:07
React createElement具有以下语法(可能是其中一种语法)
React.createElement(elementType, props/attributes, value);
例如
React.createElement('li', {id:'list_one'}, 'List one');
上面的示例创建了下面的元素
<li id="list_one">List one</li>
然而,由于第二个参数也是一个道具,最好将Id作为道具传递,而不是像上面那样将它固定在某个东西上。通过传递道具,我们可以控制元素的Id。
https://stackoverflow.com/questions/49359292
复制