我有一种情况,我有一个 for 循环,它从我的数据模型创建我的 html 表,该数据模型从 SQL Server Express 获取数据。我想知道是否可以创建一个自动刷新方法,其中表数据仅刷新而不刷新整个页面,如果没有,那么也许 OnClick 按钮将从数据模型中检索最新数据并相应地更新表的方法。
我是 blazor 和 C# 的新手,因此任何帮助将不胜感激,我当前的页面结构目前如下所示:
@page "/employees"
@using DataLib;
@inject IEmployeeData _db
@if (employees is null)
{
<p style="color:white;"><em>Loading . . .</em></p>
}
else
{
<table class="table" id="myTable">
<thead>
<tr>
<th>Entry Date</th>
<th>Employee</th>
</tr>
</thead>
<tbody>
@foreach (var employee in employees)
{
<tr>
<td>@employee.EntryDate</td>
<td>@employee.POI</td>
</tr>
}
</tbody>
</table>
}
@code{
private List<EmployeeModel> employees;
protected override async Task OnInitializedAsync()
{
employees = await _db.GetEmployee();
}
}
当我加载此页面以及进行手动刷新时,上述内容非常有效。
你们有什么办法可以帮助我吗?
Thanks.
不确定这是您可以尝试的瞄准屁股吗?
@inject IEmployeeData _db
@if (employees is null)
{
<p style="color:white;"><em>Loading . . .</em></p>
}
else
{
<table class="table" id="myTable">
<thead>
<tr>
<th>Entry Date</th>
<th>Employee</th>
</tr>
</thead>
<tbody>
@foreach (var employee in employees)
{
<tr>
<td>@employee.EntryDate</td>
<td>@employee.POI</td>
</tr>
}
</tbody>
</table>
<button @onclick="GetEmployees"> Refresh Employee List</button>
}
@code{
private List<EmployeeModel> employees;
protected override async Task OnInitializedAsync()
{
GetEmployees()
}
private async void GetEmployees()
{
employees.Clear();
employees = await _db.GetEmployee();
StateHasChanged();
}
祝你好运,
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)