Ich bin mit der Reaktion js beginnen, und ich habe 2 Probleme.zeigt eine andere Komponente auf Zustandsänderung und für Schleife Reagieren js
1) Ich versuche, eine Tabelle zu zeigen, die in einer anderen Klasse ist, indem Sie auf die Schaltfläche Anzeigen klicken, sollte eine Tabelle angezeigt werden. Das Problem ist, dass die Tabelle nicht angezeigt wird, selbst wenn der Status zum Anzeigen der Tabelle wahr ist.
2) In der Tabelle I mit Informationen ein Array bin vorbei wie dies
Object {1: Object, 2: Object, 3: Object, 4: Object, 5: Object, 6: Object}
1 capital_payment :"100",
currency: "2"
dudedate : "2017-08-20"
Aber ich bin nicht sicher, wie eine for-Schleife verwenden und diese Informationen zu machen. Ich verwende eine console.log, um zu sehen, was drin ist, aber mein Code geht nicht, bis die neue Klasse angezeigt wird, um die Tabelle anzuzeigen.
Hier sind die Codes.
var Heading = React.createClass({
getInitialState: function() {
return {
data : [],
amount : 1000,
firstMonth : 0,
showtable : false <--------- HERE IS THE SHOW TABLE STATE
};
},
showTable : function(){
console.log('I am here');
this.setState({showtable : !this.state.showtable}); <----CHANGING STATE HERE
console.log(this.state.showtable);
},
render : function(){
var amount = this.state.amount;
var firstMonth = this.state.firstMonth;
return(
<div className="container">
<div className="row">
<div className="col-xs-4 col-xs-offset-4">
<div className="form-group">
<label>How much <span>{amount}</span> </label>
<input type="text" className="form-control" placeholder="Amount" value={amount} onChange={this.handleChange} />
</div>
<button type="submit" className="btn btn-success" onClick={this.loadCommentsFromServer} >Submit</button>
<button type="submit" className="btn btn-success" onClick = {this.showTable} > Show table </button>
<hr />
<!--- HERE IS WHERE THE NEW CLASS SHOULD SHOW UP IF TABLE IS CHANGED -->
{ this.state.showtable ? <tableView data={this.state.data}/> : null }
</div>
</div>
</div>
);
}
});
// HERE IS THE TABLEVIEW, AND I HAVE NO CLUE HOW TO DO A FOR LOOP TO RENDER INFORMATION TO THE TABLE
var tableView = React.createClass({
render: function() {
console.log(this.props.data);
return (
<table className="table">
<thead>
<tr>
<th>amount</th>
<th>duedate</th>
<th>currency</th>
</tr>
</thead>
<tbody>
<tr>
<!-- Need to know how the forloop is done, is there a easier way? -->
{this.props.data.map(function(info) {
return (
<tr key={info}>
{info.capital_payment},
{info.currency},
{info.duedate}
</tr>
);
})}
</tr>
</tbody>
</table>
);
}
});
ReactDOM.render(
<div>
<Heading
name="React JS"
>
</Heading>
<tableView />
</div>
, document.getElementById('reactBinding'));
Was Sie mit der Karte in Tableview hat es eine normale Praxis ist. Warum Tisch nicht gezeigt? Irgendwelche Fehler? – Andrew
@Andrew Ich bin nicht sicher, warum der Tisch nicht angezeigt wird, und ich habe nur eine Forloop von einem anderen Stapel über Flow-Post nach ihm verwendet.Nein, es gibt keinen Fehler. Ich Konsole protokolliert die Statechange, und es zeigt True und False, wenn die Schaltfläche für die Show-Tabelle angeklickt wird, aber die Tabelle nicht angezeigt wird. Ich bekomme nicht einmal einen Fehler. –