angular - 我正在尝试构建一个动态元流对象,该对象在运行之前等待一些流完成
问题描述
问题:
我有许多流输入服务。当单击按钮时,当前订阅其服务流的所有活动组件,更新所述流。我需要遍历该服务中的所有流,并从不为空的流中构建一个 json 对象。
流服务
masterSubmit$: BehaviorSubject<string> = new BehaviorSubject(null);
addForm$: BehaviorSubject<model> = new BehaviorSubject(null);
addSubForm$: BehaviorSubject<otherModel> = new BehaviorSubject(null);
RxJSOperatorThatEmitsAllStreamsAtSameTime(
masterSubmit$,
addForm$,
addSubForm$,
).subscribe((data) => {
if(data[0] == null){
return;
}
if(data[1] != null){
jsonObject.properties = {data[1]}
}
etc..
if(data[0] == 'postNewThingy'){
this.apiStuff.postThingy(jsonObject);
}
})
这就是我想要的,任何建议都会很棒!谢谢!
解决方案
嗨,您可以使用 combineLatest RXJS 运算符等待所有调用完成
combineLatest(masterSubmit$,
addForm$,
addSubForm$,).subscribe(
([masterSubmit, addForm, addSubForm]) => {
console.log(
`masterSubmit: ${masterSubmit},
addForm: ${addForm},
addSubForm: ${addSubForm}`
);
}
);
推荐阅读
- python - 数字猜谜游戏的编码问题
- c++ - 带有 Protobuf 序列化的 C++ Hazelcast:字符串不是 UTF-8 格式的
- java - 扩展现有 Mapstruct 接口以添加其他映射方法
- node.js - 不正确的 Node.js 方法调用仍然可以编译
- java - 数组和字符串未解析为变量
- linkedin - 通过 LinkedIn 开发人员合作伙伴计划访问 LinkedIn r_fullprofile?
- amazon-web-services - 如何设置电子邮件警报(作业状态)以接收特定 AWS Glue 作业的状态
- bash - 我可以使用什么类型的 unix 命令从“ls -ld”捕获权限并以某种格式输出?
- css - 如何在没有类或 ID 或共享全局类/ID 的情况下隐藏 li 和标签
- spring - 使用 Spring Reactive WebClient 对同一服务 API 进行多次调用的正确方法?