1.嵌套組件之父組件的定義:app
export default class Examines extends Component{ componentWillMount() { console.log("aaaaaaaa"); var data2={ action:"queryTaskOfManager" }; Common.getData(JSON.stringify(data2),function (ret) { alert(ret); var data3={ name:ret.msg.name, }; alert(data3); }); } render(){ var items = []; for (var i = 0; i < 10; i++) { items.push(<OneTask/>); //這裏父組件Examines,嵌套了子組件<OnTask/> } return( <div style={{ background: '#ECECEC', padding: '30px' }} onLoad={this.componentWillMount}> <Row gutter={16}> {items} </Row> </div> ); } }
2.嵌套組件之子組件的定義:this
class OneTask extends React.Component{ constructor(props) { super(props); this.state = { date: '', person:'', work:'', applyclass:'', otherinfo:'', applytime1:'', applytime2:'', timecount:'' } } render(){ return ( <Col span={8}> <Card title="請假申請單" bordered={false}> <p>申請人:{this.state.person}</p> <p>申請時間:{this.state.date}</p> <p>崗位:{this.state.work}</p> <p>請假類型:{this.state.applyclass}</p> <p>請假備註:{this.state.otherinfo}</p> <p>請假時間:{this.state.applytime1}到,{this.state.applytime2}</p> <p>共請假:{this.state.timecount}天</p> <Row gutter={16}> <Col span={12}> <Button type="primary" id="apply">批准</Button> </Col> <Col span={12}> <Button type="danger" style={{marginLeft:30}} id="cancel">不批</Button> </Col> </Row> </Card> </Col> )} }
3.for循環渲染子組件:spa
render(){ var items = []; for (var i = 0; i < 10; i++) { items.push(<OneTask/>); } return( <div style={{ background: '#ECECEC', padding: '30px' }} onLoad={this.componentWillMount}> <Row gutter={16}> {items} </Row> </div> ); }