我正在为我正在制作的网站开发表格组件。我希望能够在一页上创建、更新、添加和删除表中的条目。我还将在整个网站上使用这个组件,并使用多种类作为输入。我去这里学习如何做到这一点。我还认为表中的每一行都有一个内部组件是明智的。到目前为止,这是我的代码:
可编辑类.Razor
@using WbotV2.Data
@using System
@using System.Collections
@using System.Reflection
@typeparam TItem
<tr>
@foreach (var datum in Data)
{
<td>@datum</td>
}
<td><button class="btn btn-success">Edit</button></td>
<td>@ChildContent</td>
</tr>
@code {
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public TItem Item { get; set; }
public List<string> Data;
public bool Editable = false;
protected override async Task OnInitializedAsync()
{
Data = GetData(Item);
}
public static List<string> GetData<T>(T instance)
{
List<string> ret = new List<string>();
FieldInfo[] infos = typeof(T).GetFields();
foreach …Run Code Online (Sandbox Code Playgroud)