【发布时间】:2020-12-27 00:51:16
【问题描述】:
假设我定义了 2 个接口,如下所示:
export interface SpecFormatA{
CPUFullname: string;
CPUmanufacturer: string;
Physicalmemory: number;
Pagesize: number;
OSinfo: string;
Videocontroller: Array<string>
}
export interface SpecFormatB{
CPUname: string;
OSinfo: string;
RAM: string;
VideoController: Array<string>;
}
我调用一个方法并得到SpecFormatA 的可观察性。我想格式化接收到的 observable 并创建一个新的 observable SpecFormatB 并从我的方法中返回它。
有什么简单的方法吗?
我的转换逻辑是这样的:
SpecFormatB.CPUname = SpecFormatA.CPUFullname
SpecFormatB.OSinfo = SpecFormatA.OSinfo
SpecFormatB.RAM = `${SpecFormatA.Physicalmemory / Math.pow(1024, 3)} GB`
SpecFormatB.VideoController = SpecFormatA.VideoController
【问题讨论】:
-
您可以格式化从可观察对象返回的值,而不是可观察对象本身
标签: angular typescript rxjs rxjs-observables