2015-05-12 5 views
17

React.createElement एक प्रसार लेता है" बच्चों "पैरामीटर`React.createElement` बच्चों पैरामीटर (jsx के बिना)

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? 
    } 
}) 
का उपयोग करने पर किसी भी प्रलेखन नहीं मिल सकता है

मुझे यकीन है कि यह वास्तव में वास्तव में एक सरल जवाब है।

उत्तर

31

बच्चों, एक घटक के लिए पारित या तो JSX घोंसले के माध्यम से या React.createElement करने के लिए तृतीय + तर्क के माध्यम से, this.props.children के रूप में घटक में दिखाई देता है:

var MyLabel = React.createClass({ 
    render: function() { 
    return React.createElement("label", {className: "label"}, 
     React.createElement("span", {className: "label"}, this.props.label), 
     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/; दस्तावेज़: http://facebook.github.io/react/docs/multiple-components.html#children

+0

आह धन्यवाद। 'प्रोप' के अंदर * अंदर * कभी नहीं सोचा –

संबंधित मुद्दे