Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度js中的动态列表+;类型脚本_Javascript_Angularjs_Json_Typescript_Angular2 Directives - Fatal编程技术网

Javascript 角度js中的动态列表+;类型脚本

Javascript 角度js中的动态列表+;类型脚本,javascript,angularjs,json,typescript,angular2-directives,Javascript,Angularjs,Json,Typescript,Angular2 Directives,我想使用anguler js创建以下动态列表 根据my的要求,列集(如水果、蔬菜)可以根据数据集进行动态更改。我想从json文件加载数据。 例: 我尝试了许多方法,但无法创建动态表。如何创建这种类型的表?您需要使表结构如下: <table border="1" cellpadding="10" cellspacing="0"> <thead> <tr> <th rowspan="2">Store</th> <

我想使用anguler js创建以下动态列表

根据my的要求,列集(如水果、蔬菜)可以根据数据集进行动态更改。我想从json文件加载数据。 例:


我尝试了许多方法,但无法创建动态表。如何创建这种类型的表?

您需要使表结构如下:

<table border="1" cellpadding="10" cellspacing="0">
<thead>
  <tr>
    <th rowspan="2">Store</th>
    <th rowspan="2">Store Name</th>
    <th colspan="4">Vegetables</th>
    <th colspan="4">Fruit</th>
  </tr>
  <tr>
    <th>Ordered</th>
    <th>Delivery</th>
    <th>FR</th>
    <th>Gap</th>
    <th>Ordered</th>
    <th>Delivery</th>
    <th>FR</th>
    <th>Gap</th>
  </tr>
</thead>
<tbody>
  <tr *ngFor="let item of items">
    <td>item.storeCode</td>
    <td>item.storeName</td>
    <td>item.Vegetables.Ordered</td>
    <td>item.Vegetables.Delivery</td>
    <td>item.Vegetables.FR</td>
    <td>item.Vegetables.Gap</td>
    <td>item.Fruit.Ordered</td>
    <td>item.Fruit.Delivery</td>
    <td>item.Fruit.FR</td>
    <td>item.Fruit.Gap</td>
  </tr>
</tbody>

商场
店名
蔬菜
果
命令
传送
FR
缺口
命令
传送
FR
缺口
item.storeCode
item.storeName
点的菜
项目.蔬菜.交货
item.vegets.FR
项目.蔬菜.缺口
点了水果
项目.水果.交货
item.Fruit.FR
项目.水果.缺口


您可以看到正在运行的jsBin

谢谢@Rohit Sharma。但当另一个类别(如水果)可用时会发生什么。根据上述结构,我们必须更改代码。然后您需要将类别存储在数组中,并相应地生成动态标题。如果您希望有人能够回答您的问题,您需要显示您尝试了什么以及失败的地方。你的问题有点太大了,如果你想让别人花时间回答你,你需要更具体一点,否则,没人知道从哪里开始。
<table border="1" cellpadding="10" cellspacing="0">
<thead>
  <tr>
    <th rowspan="2">Store</th>
    <th rowspan="2">Store Name</th>
    <th colspan="4">Vegetables</th>
    <th colspan="4">Fruit</th>
  </tr>
  <tr>
    <th>Ordered</th>
    <th>Delivery</th>
    <th>FR</th>
    <th>Gap</th>
    <th>Ordered</th>
    <th>Delivery</th>
    <th>FR</th>
    <th>Gap</th>
  </tr>
</thead>
<tbody>
  <tr *ngFor="let item of items">
    <td>item.storeCode</td>
    <td>item.storeName</td>
    <td>item.Vegetables.Ordered</td>
    <td>item.Vegetables.Delivery</td>
    <td>item.Vegetables.FR</td>
    <td>item.Vegetables.Gap</td>
    <td>item.Fruit.Ordered</td>
    <td>item.Fruit.Delivery</td>
    <td>item.Fruit.FR</td>
    <td>item.Fruit.Gap</td>
  </tr>
</tbody>