【问题标题】:How to bind a collection to a table in Blazor?如何将集合绑定到 Blazor 中的表?
【发布时间】:2020-12-06 10:22:21
【问题描述】:

我有一个 razor 组件,其中包括一个简单的表,我想将其用作输入表,如下所示:

<label for="dependencies">Abhängigkeiten</label>
<table class="table table-striped">
  <tr>
    <th scope="col">Name</th>
    <th scope="col">Version</th>
    <th scope="col">Entfernen</th>
  </tr>
</table>

在代码部分中,我有一个 IEnumerable&lt;T&gt; 类型的属性,我想动态绑定到表,因此集合的内容会绑定到表。我必须这样做哪些选项?

【问题讨论】:

    标签: blazor blazor-client-side blazor-webassembly


    【解决方案1】:
    @foreach(var item in AllItems)
    {
      <tr @key=item>
        <td>@item.Name
      </tr>
    }
    

    如果需要,你也可以&lt;InputText @bind=item.Name/&gt;

    【讨论】:

      猜你喜欢
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 2013-03-22
      相关资源
      最近更新 更多