嵌套在角度7中的循环

时间:2019-04-04 12:55:39

标签: arrays json angular

this.listz= this.list;
this.filtered= this.allTitles;
const list: string[] =[];

this.allTitles.forEach ((value) => {
  const firstLetter = value.titleName.substr(0, 1 ).toUpperCase();
  const index = list.indexOf(firstLetter);
  if (firstLetter.match(/[A-Z]/i)) {
    value.list = firstLetter; 
  } else {
    value.list = '#';
    if (list.indexOf('#') === -1) {
      list.push('#');
    }
  }
  if (index === -1 && (firstLetter.match(/[A-Z]/i))) {
    list.push(firstLetter);
    this.list = list.sort();
  }
});

<div *ngFor="let list of listz"> <div>{{list}}</div> <div class="title-card-group" *ngFor="let titleGroup of filtered | group | order"> <div *ngIf="titleGroup.list == list"></div> </div> </div>

我有一个Json对象,参考此JSON对象,我建立了一个数组,我试图用嵌套的for循环(角度7)来迭代HTML中的逻辑,当嵌套时,该逻辑不起作用,单独使用时,逻辑有效

在加载页面时,我得到一个JSON对象作为响应,我用JSON对象构建了一个数组,该数组具有唯一值,并且我试图相对于该数组显示JSON对象,循环失败了

请帮助我解决此问题,谢谢!

编辑: 从注释中添加JSON:

[
   {
      "titleName":"Campione! - Volume 1 - Heretic God",
      "titleId":"third/reader/l07261",
      "list":"C"
   },
   {
      "titleName":"Dampione! - Volume 1 - Heretic God",
      "titleId":"third/reader/l0726",
      "list":"D"
   },
   {
      "titleName":"Fampione! - Volume 1 - Heretic God",
      "titleId":"third/reader/l072",
      "list":"F"
   },
   {
      "titleName":"_ampione! - Volume 1 - Heretic God",
      "titleId":"third/reader/l07",
      "list":"#"
   },
   {
      "titleName":"1ampione! - Volume 1 - Heretic God",
      "titleId":"third/reader/l0",
      "list":"#"
   }
]

0 个答案:

没有答案