0
我有一個React應用程序,我正在學習React,它增加了收入,支出和日誌事務。如何在此React應用程序中設置編輯項目功能?
我很擔心如何設置編輯條目的能力。
所以我有一系列的每個條目。支出項陣營等級如下表所示:
const Expenditure = React.createClass({
renderExpenditure(key) {
const details = this.props.cashbook[key];
return(
<tr className="item" key={key}>
<td><strong>{details.name}</strong></td>
<td><strong>{h.formatPrice(details.amount)}</strong></td>
<td>{details.category}</td>
<td>{details.type}</td>
<td>{details.date}</td>
<td><button className="remove-item" onClick={this.props.removeCashflow.bind(null, key, 'expenditure')}>Remove</button></td>
</tr>
);
},
render() {
return(
<div className="expenditure">
<table id="exp-table">
<tbody>
{Object.keys(this.props.cashbook || {}).map(this.renderExpenditure)}
</tbody>
</table>
</div>
);
}
});
而且removeCashflow,在主應用程序組件,看起來像:
removeCashflow(key, type) {
this.state.cashbook[type][key] = null;
this.setState({
cashbook: { [type]: this.state.cashbook[type] }
});
},
沒有人有任何指針或建議,以建立最好的辦法在React中編輯條目的能力?
不確定從哪裏開始。
謝謝:)
謝謝@Mijamo - 我不能完全鍛鍊這將如何設置...這將取代'{Object.keys(this.props.cashbook || {})。map(this.renderExpenditure)}' ? –
準確地說,它將被替換爲 {Object.keys(this.props.cashbook || {})。map(function(key){return })} –
Mijamo
你明星,謝謝你,會給這個bash! –