【发布时间】:2018-11-27 13:13:41
【问题描述】:
在 Angular 应用程序中,我使用 HttpClient 和 RxJS 运算符进行一些 API 调用。例如:
return this.httpClient.put(url, JSON.stringify(treeOptions))
.pipe(
map(this.extractTreeData),
catchError(this.handleError)
);
extractTreeData 方法基本上改变了 API 返回的一些属性:
private extractTreeData(res: any) {
let apiTree = res.data; // The tree comes inside the 'data' field
let newTree : any;
try {
let str = JSON.stringify(apiTree);
str = str.replace(/"children"/g, '"items"');
str = str.replace(/"allowdrag"/g, '"allowDrag"');
newTree = JSON.parse(str);
} catch(e) {
// Error while parsing
newTree = null;
}
return newTree || {};
}
我需要根据树的类型进行更多更改。我怎样才能将这种类型传递给映射方法?我的意思是:
[...]
.pipe(
map(this.extractTreeData), <== HOW TO PASS VARIABLE 'treeType' TO extractTreeData
[...]
提前致谢,
【问题讨论】: