Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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
C# 如何在Angular 2中逐个单元格构建表格行_C#_Angular_Asp.net Web Api - Fatal编程技术网

C# 如何在Angular 2中逐个单元格构建表格行

C# 如何在Angular 2中逐个单元格构建表格行,c#,angular,asp.net-web-api,C#,Angular,Asp.net Web Api,比如说,我有一张桌子: +--------+----------+---- | Device | Serial # | +--------+----------+---- | Cam1 | AB123 | +--------+----------+---- 因为我事先不知道要显示的列,所以我只为每个单元格发送一对key/vale来构造表 这就是我用C代码获取数据的方式 在razor中,我只需循环浏览列表 @foreach(var row in Model) { <tr>

比如说,我有一张桌子:

+--------+----------+----
| Device | Serial # |
+--------+----------+----
| Cam1   | AB123    |
+--------+----------+----
因为我事先不知道要显示的列,所以我只为每个单元格发送一对key/vale来构造表

这就是我用C代码获取数据的方式

在razor中,我只需循环浏览列表

@foreach(var row in Model)
{
  <tr>
       @foreach(var cell in row)
       {
           <td>@cell.Value</td>
       }
  </tr>
}
@foreach(模型中的变量行)
{
@foreach(行中的var单元格)
{
@单元格值
}
}
在Angular中,我不知道如何使用指令实现这一点

<tr *ngFor="let myInnerList of myTable">
    //I'd like to loop through the each inner list to build each table cell
</tr>

//我想循环遍历每个内部列表来构建每个表单元
谢谢你的帮助

编辑 有可能得到这样的东西吗?i、 e如果列是ID,则显示复选框以便可以选择该行

@foreach(var cell in row)
{
   if(cell.Key == "Id")
   {
     <td><input type="checkbox" id="row_@cell.Value" /></td>
   }
   else
   {
       <td>@cell.Value</td>
   }
}
@foreach(行中的变量单元格)
{
如果(cell.Key==“Id”)
{
}
其他的
{
@单元格值
}
}

这样,每行的第一个单元格都会显示一个复选框。

我不确定您要显示什么,您可以编写这个,但它取决于您的数组在每个数组中的排序是否相同。如果不是这样,您可以添加代码使其成为这样,或者创建一个过滤器

这相当于你问题中的c代码

<tr *ngFor="let row of myTable">
    <td *ngFor="let col of row">
      {{col.value}}
    </td>
</tr>

{{col.value}}

什么是MyListFlists?在示例数据中,您有
myTable
,为什么
*ngFor
中没有引用该数据?“你不懂怎么做?”伊戈尔,谢谢你指点。这很有效。我已经更新了问题(请参阅更新)。如果列是
ID
,则应显示
复选框。如果你认为我应该开始一个新的话题,我会去做的。@Richard77-那最好在一个新问题中解决。您可以使用
*ngIf
ngModel
输入
进行值绑定。
@foreach(var cell in row)
{
   if(cell.Key == "Id")
   {
     <td><input type="checkbox" id="row_@cell.Value" /></td>
   }
   else
   {
       <td>@cell.Value</td>
   }
}
<tr *ngFor="let row of myTable">
    <td *ngFor="let col of row">
      {{col.value}}
    </td>
</tr>