angular - 如何获取具有相同参数的嵌套对象数组
问题描述
有人可以帮我在文章数组的内容数组中显示所有标题和内容吗
以下响应来自数据库,我将该响应等同于作者详细信息,只是我给了这样的名字。
authordetails:any=[];
this.authordetails=[
{"_id": "5c1a34ce5e2de421d8e060e5", "article":[
{"content": [
{"content": "hh", "title": "Abstract" },
{"content": "gg", "title": "Introduction" },
{"content": "ii", "title": "Models" }
];
我试过这样
this.authordetails[0].article[0].content[0].title
这意味着它在内容数组中仅显示标题的 0 对象。
但我需要所有对象的内容数组中的标题和内容。
提前致谢
解决方案
它应该是这样的(伪代码)
for (i=0;this.authordetails[0].article.length;i++) {
let innerObject = this.authordetails.article[i];
let content = innerObject.content;
let title = innerObject.title;
// more logic goes here
}
推荐阅读
- python - 多处理池不执行功能
- powershell - powershell中的计时器事件在远程会话中不起作用
- swift - 使用添加的 url 方案时,Urls 不会打开
- python - IntegrityError:数据类型不匹配
- java - 所以这是我的程序,但我不知道如何将 :40036 的所有数字仅重定向或仅重定向到新数据文件中?
- javascript - 使用 Firebase 云功能有条件地发送通知?
- r - 绘图不显示负值
- bash - Git-Bash 文件查找取决于文件类型
- excel - 如何从用户窗体向变量添加文本框值?
- bash - 是否可以使用 write com.apple.dock tilesize 在 Mojave/Sierra 上运行设置 Dock 的大小?