ReactJS - 将数组中的数据推送到数组中的最佳方法是什么?
ReactJS - What is the best way to push data in an array within an array?
我想将数据推送到对象(订单)中。订单中包含产品、零件和印刷品的数组。我只想在打印件中推送数据。这意味着我有 2 个按钮,第一个按钮将推送所有订单的数据,而第二个按钮将仅推送一部分订单,即打印。你可以看到印刷品正在订购中。你能建议我如何做到这一点吗?
下面是我的订单数组。现在我只想推一个数据到orders.prints
orders: [{
product: {
pType: '',
name: '',
brand: '',
color: '',
files: []
},
parts: [],
prints: [{
name: '',
width: '',
height: '',
colors: ''
}],
breakdown: [{
size: '',
quantity: 0
}]
}]
通过在订单中添加值来设置索引来实现它。订单[0]
onAddPrint = () => {
var newPrints = this.state.orders;
newPrints[0].prints.push({
name: 'Test',
width: 'Test',
height: 'Test',
colors:
});
this.setState({
orders: this.state.orders.splice(0, 1, newPrints)
});
}
我想将数据推送到对象(订单)中。订单中包含产品、零件和印刷品的数组。我只想在打印件中推送数据。这意味着我有 2 个按钮,第一个按钮将推送所有订单的数据,而第二个按钮将仅推送一部分订单,即打印。你可以看到印刷品正在订购中。你能建议我如何做到这一点吗?
下面是我的订单数组。现在我只想推一个数据到orders.prints
orders: [{
product: {
pType: '',
name: '',
brand: '',
color: '',
files: []
},
parts: [],
prints: [{
name: '',
width: '',
height: '',
colors: ''
}],
breakdown: [{
size: '',
quantity: 0
}]
}]
通过在订单中添加值来设置索引来实现它。订单[0]
onAddPrint = () => {
var newPrints = this.state.orders;
newPrints[0].prints.push({
name: 'Test',
width: 'Test',
height: 'Test',
colors:
});
this.setState({
orders: this.state.orders.splice(0, 1, newPrints)
});
}