json - Getting .apply is not a function
问题描述
does anyone know why I'm getting:
ERROR TypeError: _this.user_data.apply is not a function
While tying to populate user_data with a mapped result from a JSON file
user_data: any;
this.testService.getTestWithObservable()
.map( result => result.map( i => i.users.data) )
.subscribe(
res => {
this.user_data = [];
res.forEach(i => this.user_data(...i));
console.log(this.user_data);
}
);
}
JSON
[{
"id": 1,
"users": {
"user_id": 14,
"data": [{
"name": "James",
"age": 20
},
{
"name": "Damien",
"age": 25
}]
}
}
{
"id": 2,
"users": {
"user_id": 11,
"data": [{
"name": "James",
"age": 20
},
{
"name": "Damien",
"age": 25
}]
}
}]
I can't find anything related to this error/code
解决方案
解决了:
TS
res => {
this.user_data= res;
}
HTML
<div *ngFor="let data of user_data">
<div *ngFor="let x of data">
{{ x.name}}
</div>
</div>
推荐阅读
- d3.js - 用节点的子节点检查父节点
- javascript - 在 JS 中的元素之前不会显示在前面添加多个元素
- python - 当使用 numpy.polyfit 时,协方差矩阵的对角线指的是哪些系数
- visual-studio-code - 如何使用 vscode API 在悬停消息上应用样式和 html 标签?
- python - 这个 Python 代码片段的时间复杂度是多少?
- mysql - 编写查询以升序计算所有车型的国家销售额以及 2020 年生成的 total_sales
- sorting - 当y轴显示值范围时如何订购yticks
- app-config - 当我禁用 sql server 时,运行 c# app 的 .exe 文件会导致错误
- mysql - node.js中的数据库连接,多个脚本文件
- ios - 如何在 IOS 中将浮动操作按钮带出应用程序并使其运行可见、可移动和可点击?