作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从模态中获取数据,我需要检查结果并根据许多条件确定要触发哪个外部函数。
我已经验证了传回的数据格式正确,并且应该触发一系列 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/
我是一名优秀的程序员,十分优秀!