React.createElement传递一个“children”参数
var d = React.DOM; React.createElement(LabeledElement,{label: "Foo"},d.input({value: "foo"}) )
但是我找不到任何关于如何实际使用它的文档
var LabeledElement = React.createClass({ render: function() { return d.label({},d.span({classNames: 'label'},this.props.label),//How to place children here? } })
我确定这有一个非常简单的答案.
孩子们通过JSX嵌套或者通过React.createElement的第三个参数传递给一个组件,在组件中显示为this.props.children:
原文链接:https://www.f2er.com/react/301200.htmlvar MyLabel = React.createClass({ render: function() { return React.createElement("label",{className: "label"},React.createElement("span",this.props.children ); } }); var App = React.createClass({ render: function() { return React.createElement(MyLabel,{label: "Here is the label prop"},React.createElement("div",{},React.createElement("input",{type: "text",value: "And here is a child"}) ) ); } });
示例:http://jsfiddle.net/BinaryMuse/typ1f2mf/; docs:http://facebook.github.io/react/docs/multiple-components.html#children