reactjs – 将props从模板传递到react.js根节点
发布时间:2020-12-15 20:42:25 所属栏目:百科 来源:网络整理
导读:我可能错过了一些东西,但是在这里.如果我有: var Swoosh = React.createClass({ render: function() { return ( div className="swoosh" Boom. /div ); }});React.renderComponent( Swoosh /,document.getElementById('content')); 我可以将道具设置为挂载
我可能错过了一些东西,但是在这里.如果我有:
var Swoosh = React.createClass({ render: function() { return ( <div className="swoosh"> Boom. </div> ); } }); React.renderComponent( <Swoosh />,document.getElementById('content') ); 我可以将道具设置为挂载点(其中id =’content’)的属性吗? <div id='content' foo='alice' bar='has' bav='a cat' /> <!-- have foo,bar & bav available as props in <Swoosh />? -->
不,当然你可以做:
var container = document.getElementById('content'); React.renderComponent( <Swoosh foo={container.getAttribute('foo')} bar={container.getAttribute('bar')} bav={container.getAttribute('bav')} />,container ); (或者如果你想使用像https://stackoverflow.com/a/5282801/49485这样的属性dict,那么你可以做Swoosh(属性)). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |