编辑:我误读了你的问题,好像你想要一个 Reflux 答案,而我只给出了一个 React 答案。无论如何,我会保持这个以供将来参考。
我会这样做的方式是存储一系列发票的单个商店。所以我会让我的服务器 API 输出如下:
[
{
invoice_no: 1,
delivery: {
// delivery details
},
customer: {
// customer details
}
products: [
{
product_no: 1,
product_details: {
...
}
},
{
product_no: 5,
product_details: {
...
}
}
]
},
{
invoice_no: 2,
...
}
]
然后将其存储在<App>
组件的状态中。我的 React 代码大致如下所示:
var App = React.createClass({
getInitialState: function() {
return { invoices: [] };
},
onComponentDidMount: function() {
// make an ajax call to server to get
// invoices data. Then on success:
// this.setState({ invoices: data });
},
render: function() {
<div>
<InvoiceTabs invoices={this.state.invoices} />
</div>
}
});
// Everything here on out is just using props, so it's immutable data.
var InvoiceTabs = React.createClass({
render: function() {
var InvoiceComponents = this.props.invoices.map(function(invoice) {
return (
<Invoice invoice={invoice} />
);
});
}
});
var Invoice = React.createClass({
render: function() {
var invoice = this.props.invoice;
return (
<li>
<ProductsList products={invoice.products} />
<DeliveryInfo delivery={invoice.delivery} />
<InvoiceCalculator />
</li>
)
}
});
// various other components