angular - 来自 Api 的数据顺序不正确?
问题描述
在我的应用程序中,我使用 REST API 从数据库中获取数据。当我在 Postman 中检查 API 请求的响应时,它显示一种格式,当我得到响应并记录数据时,它显示另一种与我要求的完全不同的顺序。
可能是什么问题?请指导我。
邮递员回复:
{
"testdata": {
"attributes": {
"year": {
"2019": [
{
"id": 1,
"y": 2019,
"q": 1,
}
],
"2018": [
{
"id": 2,
"y": 2018,
"q": 1,
},
{
"id": 3,
"y": 2018,
"q": 4,
}
]
},
}
}
}
我的组件.ts
this.testService.getdata().subscribe(d => {
console.log(d.testdata.attributes.year);
});
我得到这个结果
2018 Array(2)
2019 Array(1)
代替
2019 Array(1)
2018 Array(2)
测试服务.ts
getdata() {
return this
.http
.get(`${environment.apiUrl}` + '/test/data');
}
解决方案
推荐阅读
- arduino - arduino mega上的led代码内置led发光
- ipfs - IPFS 的保密性?
- pine-script - 这个简单的海龟策略没有位置条目
- reactjs - 未处理的拒绝 (ChunkLoadError):加载块 1 失败
- c++ - 我可以使用现代 C++ (STL/Boost) 进行多路复用吗?
- javascript - 导航目录展开和折叠 Bootstrap 4
- c# - 接口 - 在这种情况下是否值得强制使用它们?
- javascript - 显示数据库数据(纬度,经度)并使用 laravel 将它们打印为谷歌地图上的标记
- javascript - 如何确定 WebRTC dataChannel.send 是否已交付?
- apache-spark-sql - Spark DataFrame 提示函数的可能值是什么?