首页 > 解决方案 > 如何获取具有相同参数的嵌套对象数组

问题描述

有人可以帮我在文章数组的内容数组中显示所有标题和内容吗

以下响应来自数据库,我将该响应等同于作者详细信息,只是我给了这样的名字。

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 对象。

但我需要所有对象的内容数组中的标题和内容。

提前致谢

标签: angular

解决方案


它应该是这样的(伪代码)

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
}

推荐阅读