首页 > 解决方案 > 使用 2 个 json 的 Angular ngprime 表

问题描述

我是 ngprime 的新手,面临以下问题。我得到 2 个 json 用于第一列的标签,第二个 json 有第二列和第三列的数据。第二列和第三列的数据需要根据 json 1 中的 id 显示。例如。json 一个具有 id firstName 和 displayname 作为 Firstname。我需要从 json 1 中引用 id 并在 json 2 中搜索相同的 id 并在第 2 列和第 3 列中显示值。

我想使用 ngPrime p-table 来实现这一点,甚至无法启动。下面是要使用的json和要实现的输出。

我尝试搜索类似的问题,但没有任何帮助。请帮我举个例子

var json1 = [
  {id:'firstName', displayname:'First Name'},
   {id:'lastName', displayname:'Last Name'},
    {id:'age', displayname:'Age'},
     {id:'city', displayname:'City'},
      {id:'state', displayname:'State'}
      ];
      
var json2 = [
    {'firstName':'abc', 'age': 23, 'state':'MH', 'lastName': 'sharma', 'city': 'Mumbai'},
    {'firstName':'xyz', 'age': 35, 'state':'TL', 'lastName': 'Verma', 'city': 'Hyderabad'}
];
<!-- Need output as below using ngPrime <p-table><p-table> -->


<table border="1">
  <thead>
    <tr>
      <th>Description</th>
      <th>Record 1</th>
      <th>Record 1</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>First Name</td>
      <td>abc</td>
      <td>xyz</td>
    </tr>
    <tr>
      <td>Last Name</td>
      <td>sharma</td>
      <td>verma</td>
    </tr>
    <tr>
      <td>Age</td>
      <td>23</td>
      <td>35</td>
    </tr>
    <tr>
      <td>City</td>
      <td>Mumbai</td>
      <td>Hyderabad</td>
    </tr>
    <tr>
      <td>State</td>
      <td>MH</td>
      <td>TL</td>
    </tr>
  </tbody>

</table>

标签: angular

解决方案


推荐阅读