我有一个带有数量的数组对象。在这个数组中,我有一个键告诉我要填充的值(amountToFill),还有一个键告诉我已经填充的值(amountFilled)。这个想法是为了指示一个数量(amount:数量= 50;)的值,并自动使用与amountToFill相同的值填充amountFilled,但始终减少(amount:number = 50)的值是数量:数字= 50等于0。
如果amountFilled〉0,则在计算总金额的减法时必须小心。
DEMO
初步结果
amountArray =[{
option:'text',
amountToFill: 5,
amountFilled:0,
},
{
option:'text1',
amountToFill: 3,
amountFilled:1,
},
{
option:'text2',
amountToFill: 10,
amountFilled:0,
},
{
option:'text3',
amountToFill: 4,
amountFilled:1,
},
{
option:'text4',
amountToFill: 4,
amountFilled:1,
},
{
option:'text5',
amountToFill: 15,
amountFilled:0,
},
{
option:'text6',
amountToFill: 5,
amountFilled:2,
},
{
option:'text7',
amountToFill:25,
amountFilled:3,
},
{
option:'text8',
amountToFill: 15,
amountFilled:0,
},
{
option:'text9',
amountToFill: 25,
amountFilled:0,
},
{
option:'text10',
amountToFill: 5,
amountFilled:0,
}];
预期结果
amountArray1 =[{
option:'text',
amountToFill: 5,
amountFilled:5,
filled: true
},
{
option:'text1',
amountToFill: 3,
amountFilled:3,
filled: true
},
{
option:'text2',
amountToFill: 10,
amountFilled:10,
filled: true
},
{
option:'text3',
amountToFill: 4,
amountFilled:4,
filled: true
},
{
option:'text4',
amountToFill: 4,
amountFilled:4,
filled: true
},
{
option:'text5',
amountToFill: 15,
amountFilled:15,
filled: true
},
{
option:'text6',
amountToFill: 5,
amountFilled:5,
filled: true
},
{
option:'text7',
amountToFill:25,
amountFilled:12, //amount = 0
filled: true
},
{
option:'text8',
amountToFill: 15,
amountFilled:0,
filled: false
},
{
option:'text9',
amountToFill: 25,
amountFilled:0,
filled: false
},
{
option:'text10',
amountToFill: 5,
amountFilled:0,
filled: false
}];
1条答案
按热度按时间euoag5mw1#