如何处理角度6中的复杂行跨度?

问题描述

我已经从下面提到的JSON创建了表,该表工作正常。我有一定的条件需要处理。这里也提到了我使用的功能。我还附加了相同的输出图像。对相同的帮助非常感谢...在此先感谢 https://www.electronjs.org/docs/api/app#apphide-macos 条件:


    

        rows = [];
    
    generateTable() {
      if (!this.data) {
        return;
      }
    
      this.rows.push([
        {
          text: this.data.e_o_name,rowspan: 0
        }
      ]);
      let maxRowSpan = 0;
    
      this.data.matching_details.forEach((detail,i) => {
        const elemRowSpan = Math.max(detail.matching_attributes.length,1);
        maxRowSpan += elemRowSpan;
    
        if (i > 0) {
          this.rows.push([])
        }
        this.rows[this.rows.length - 1].push({
          text: detail.me_value,rowspan: elemRowSpan
        });
    
        detail.matching_attributes.forEach((attr,j) => {
          if (j > 0) {
            this.rows.push([])
          }
    
          const mail = attr.me_list[0];
          this.rows[this.rows.length - 1].push(
            {
              text: attr.me_name,rowspan: 1
            },{
              text: mail.me_email_list.map(({ me_value }) => me_value).join(','),{
              text: mail.me_percent,rowspan: 1
            }
          );
        })
      });
      this.rows[0][0].rowspan = maxRowSpan;
    }
    
    ```
    #Josn : #
    ```
    
{
   "e_id":"1234","e_o_name":"Contact_info","matching_details":[
      {
         "me_value":"value1","matching_attributes":[
            {
               "me_id":"1234","me_name":"28 sai","me_list":[
                  {
                     "me_type":"Email ID","me_email_list":[
                        {
                           "me_value":"a@gmail"
                        },{
                           "me_value":"b@gmail"
                        }
                     ],"me_percent":"100"
                  }
               ]
            },{
               "me_id":"5678","me_name":"29 meena","me_email_list":[
                        {
                           "me_value":"c@gmail.com"
                        },{
                           "me_value":",d@gmail.com"
                        }
                     ],"me_percent":"100"
                  }
               ]
            }
         ]
      },{
         "me_value":"value2","me_name":"rimzim","me_email_list":[
                        {
                           "me_value":"p@gmail"
                        },{
                           "me_value":"q@gmail"
                        }
                     ],"me_name":"ranu","me_email_list":[
                        {
                           "me_value":"t@gmail.com"
                        },u@gmail.com"
                        }
                     ],"me_percent":"100"
                  }
               ]
            }
         ]
      }
   ]
}

解决方法

似乎您想进行列(attr)级别的验证,因此在html中循环浏览时,您需要实施检查

https://stackblitz.com/edit/angular-zm1ap1?file=src/app/app.component.html

<table>
    <tbody>
        <tr>
            <th>contact</th>
            <th>ty</th>
            <th>ed</th>
            <th>mail</th>
            <th>percent</th>
        </tr>
        <tr *ngFor="let row of rows">
      <!-- check if row is empty or could add additional check such 
      row[3].text (email) is true 
       -->
      <ng-container *ngIf='row && row.length > 0'> 
      <td [attr.rowspan]='row[0].rowspan'>{{row[0].text}}</td>
      <td *ngIf='row.length > 1' [attr.rowspan]='row[1].rowspan'>{{row[1].text}}</td>
      
      <td *ngIf='row.length > 2' [attr.rowspan]='row[2].rowspan'>{{row[2].text}}</td>
      <td *ngIf='row.length > 3' [attr.rowspan]='row[3].rowspan'>{{row[3].text}}</td>
      <td *ngIf='row.length > 4' [attr.rowspan]='row[4].rowspan'>{{row[4].text}}</td>
      </ng-container>
        </tr>

    </tbody>
</table>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...