gpt4 book ai didi

javascript - 如何在 RXJS 订阅中运行多个条件

转载 作者:行者123 更新时间:2023-11-28 03:19:09 30 4
gpt4 key购买 nike

我正在从模态中获取数据,我需要检查结果并根据许多条件确定要触发哪个外部函数。

我已经验证了传回的数据格式正确,并且应该触发一系列 else if,但看起来它会跳过所有条件并且不执行任何操作。

实现此逻辑最有效的方法是什么?

我的代码:

dialogRef.afterClosed().subscribe(result => {
console.log('RESULT: ', result.delete);



if (result.isNew && !result.cancel) {
console.log('new story!');
this.boardService.updateTasks(this.job.id, [
...this.job.tasks,
result.task
]);
this.closeStories('update', this.job)
}
// means a delete has occured
else if (result.delete) {
this.closeStories('deleted triggered...')
// last story has been deleted, prompt newStory
if (this.stories.length < 2 && result === {}) {
console.log('Last story was deleted!');
this.closeStories('delete')
}
// a delete has happened
else if (this.stories.length > 1 && result === {}) {
console.log('A story was deleted!');
this.closeStories('deletedLast')
}
}
// means an update has occured
else if (result.id && !result.isNew) {
console.log('A story was Updated!');
const update = this.stories;
update.splice(result.index, 1, result.task);
this.boardService.updateTasks(this.job.id, update);
this.closeStories('update', this.job)
}
else if (result === undefined) {
return 0
}
// this.closedStoryListEmitter.emit(this.job);
console.log('hit close list event emitter!!');
});

最佳答案

//Have you checked other callbacks
dialogRef.afterClosed().subscribe(
result => {
console.log('RESULT: ', result.delete); //does this console.log executes?
//rest of the code
},
error=>{
//do something with and error
},
()=>{
//finished
}
);

关于javascript - 如何在 RXJS 订阅中运行多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59339307/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com