javascript - React JS - Render one Component in another -
i'm brand new react pardon sloppiness here. have 2 asynchronous calls api's , trying display returned data 1 component inside another.
here first component async call api:
var program = react.createclass({ getinitialstate: function(){ return{ data: [] }; }, componentdidmount(){ this.getdatafromserver('https://api.myjson.com/bins/5bdb3'); }, displayresponse: function(response) { this.setstate({ data: response }) }, getdatafromserver: function(url){ $.ajax({ type: 'get', datatype: 'json', url: url, success: function(response, i) { this.displayresponse(response) }.bind(this) }); }, render: function() { var size = 3; // show top 3 results var list = this.state.data; var result = list.slice(0, size).map(function(result, i) { return <programitem key={ } course={ result } index={ } /> }); return ( <div>{ result }</div> ); } }); var programitem = react.createclass({ render: function() { var course = this.props.course; return ( <div classname="charts-block"> <div classname="top-section"> <div classname="charts-block-title"> <p classname="title">{ course.name }</p> <button classname="edit-ico"><i classname="fa fa-pencil"></i></button> </div> <p>sales month</p> <div classname="charts"> <img src="images/graph.png" alt="stats chart" /> </div> </div> <div classname="stats-list-wrapper parent-show-more"> <table classname="stats-table header"> <tr> <th colspan={ 2 } style={{ textalign: 'right' }}>current</th> <th>1 - year</th> </tr> <tr> <td>total monlthy sales</td> <td classname="monthly-sales">{ course.totalmonthlysales }</td> <td><img src="images/spark_line.png" alt="stats spark line" /></td> </tr> </table> <div classname="show-more-table"> <div classname="stats-table plans-table"> <div> <div>price name</div> <div>current</div> <div>1 - year</div> </div> <div classname="planinfo">-- data other component here --</div> </div> </div> <div classname="click-more-row"> <span>more</span> </div> </div> </div> ); } });
and inside of <div class="planifno">
wanting "inject" data second component here:
var plan = react.createclass({ getinitialstate: function(){ return{ data: [] }; }, componentdidmount(){ this.getdatafromserver('https://api.myjson.com/bins/47axv'); }, displayresponse: function(response) { this.setstate({ data: response }) }, getdatafromserver: function(url){ $.ajax({ type: 'get', datatype: 'json', url: url, success: function(response, i) { this.displayresponse(response) }.bind(this) }); }, render: function() { var size = 7; // show top 3 results var list = this.state.data; var result = list.slice(0, size).map(function(result, i) { return <planitem key={ } plan={ result } index={ } /> }); return ( <div>{ result }</div> ); } }); var planitem = react.createclass({ render: function() { var plan = this.props.plan; return ( <tr> <td>{ plan.name }</td> <td>{ plan.sales }</td> <td></td> </tr> ); } });
any direction appriciated!
just put <plan />
there.
Comments
Post a Comment