我有这种数据,我想按顺序从logframeActionStatusRefrenceId将其发布,但结果不正确 怎么点呢? 感谢您提前帮助我
let status = [
{
id: 0,
logicalFrameworkId: this.Data.logframeId,
logFrameActionStatusReferenceId: 10,
remarks: 'ACCEPTED->PBO-PPDO',
actedByEIC: this.eic
},
{
id: 0,
logicalFrameworkId: this.Data.logframeId,
logFrameActionStatusReferenceId: 12,
remarks: 'ACCEPTED->INCLUSION',
actedByEIC: this.eic
}
];
HERE IS MY CODE but the order of the post is in random
status.forEach(data=> {
console.log('data data data');
console.log(data);
console.log('data data data');
return this.programService.saveStatus(data).subscribe(d=> {
},error => {
console.log(error);
},() => {
console.log("succesfully Save");
})
});
答案 0 :(得分:1)
在发送之前,您需要先对其进行排序。像这样:
let status = [{
id: 0,
logicalFrameworkId: this.Data.logframeId,
logFrameActionStatusReferenceId: 10,
remarks: 'ACCEPTED->PBO-PPDO',
actedByEIC: this.eic
},
{
id: 0,
logicalFrameworkId: this.Data.logframeId,
logFrameActionStatusReferenceId: 12,
remarks: 'ACCEPTED->INCLUSION',
actedByEIC: this.eic
}
].sort((a, b) => a.logFrameActionStatusReferenceId - b.logFrameActionStatusReferenceId);
然后
status.forEach(data => {
console.log('data data data');
console.log(data);
console.log('data data data');
return this.programService.saveStatus(data).subscribe(d => {
}, error => {
console.log(error);
}, () => {
console.log("succesfully Save");
})
});