angular - TypeScript 地图不是函数
问题描述
我收到错误“data.map 不是函数”。我正在映射返回 JSON 数据的 REST API 请求,但问题似乎与数据结构有关。我认为返回的数据是 data.data 并且我没有正确映射它。任何建议都会有所帮助。
这是数据结构。 JSON数据结构
这是我的服务代码。
getAlladvisors$ = this.http.get<IAdvisor[]>("http://localhost:8055/items/advisor")
.pipe(
map((data: IAdvisor[]) =>
data.map(
a =>
({
name: a.name,
id: a.id,
page: a.page,
multilang: a.multilang
})
)
),
AdvisorsandQuestions$ = this.http.get<IAdvisorsAndQuestions[]>("http://localhost:8055/items/question")
.pipe(
tap(data => console.log("Questions IDs", data))
);
getAdvisorsWithId$ = combineLatest([
this.getAlladvisors$,
this.AdvisorsandQuestions$
]).pipe(
map(([product, categories]) =>
product.map(product => ({
...product,
questionId: categories.find(c => product.id === c.id).questions_Id,
}) as IAdvisor)
),
);
这是界面
export interface IAdvisor {
id: number,
name: string,
page: string,
multilang: boolean
}
解决方案
我不确定我的答案,但对于数据:<IAdvisor []> 它可能只是数据。
getAlladvisors$ = this.http.get<IAdvisor[]>
("http://localhost:8055/items/advisor")
.pipe(
map((data: <IAdvisor[]> => {
if (data) {
console.log(data);
}
return data;
}),
catchError((error) => {
console.log(error)
}
})
推荐阅读
- flutter - 为什么滑块值返回 null?
- c# - 在 c# 中使用 HttpClientFactory 时,如何测试正在进行的 Http 调用?
- javascript - CSS:添加 Hover Overlay 会导致 div 也出现在屏幕顶部
- android - Android Crashlytics InterruptedIOException 超时
- arrays - 如何从几个数组中打印数据
- google-apps-script - 如何在 Google 表格中选择下拉列表的值时显示确认消息?
- lambda - Lambda 减少
- laravel - 如何从数据透视表中删除一行
- c# - 如何备份 WPF 数据网格使用的可观察集合?
- encryption - 为什么浏览器显示实际证书并且 mitmproxy 仍然能够解密?