C# Blazor表在更新值时正在闪烁
我正在使用blazor,我有一个简单的机制来发送请求并获得响应(每秒发送一个请求)。该响应通过事件映射到这样一个简单的模型:C# Blazor表在更新值时正在闪烁,c#,blazor,C#,Blazor,我正在使用blazor,我有一个简单的机制来发送请求并获得响应(每秒发送一个请求)。该响应通过事件映射到这样一个简单的模型: public class ResponseIdentyfication { public int ResponseNumber { get; set; } public List<Identyfication> Identyfication { get; set; } } public class Identyfication { p
public class ResponseIdentyfication
{
public int ResponseNumber { get; set; }
public List<Identyfication> Identyfication { get; set; }
}
public class Identyfication
{
public int Slot { get; set; }
public string Type { get; set; }
public State State { get; set; }
}
公共类响应身份验证
{
公共int响应枚举器{get;set;}
公共列表标识{get;set;}
}
公共类识别
{
公共int槽{get;set;}
公共字符串类型{get;set;}
公共状态状态{get;set;}
}
这是发送到razor的模板,看起来像:
<table border="1">
<thead>
<tr>Status</tr>
</thead>
<tbody>
@foreach (var responses in ResponseIdentyfication.Identyfication.ToArray())
{
<tr>
<td>@responses.ResponseNumber </td>
@foreach (var resp in @responses.Identyfication)
{
<td class="resp-status-@resp.State">@resp.Type</td>
}
</tr>
}
</tbody>
</table>
地位
@foreach(ResponseIdentityfication.Identityfication.ToArray()中的var响应)
{
@responses.ResponseNumber
@foreach(var resp in@responses.identification)
{
@响应类型
}
}
它显示了我想要的resp类型,并将其设置为css类。问题是当响应到达时,表在刷新数据时闪烁
因此,我的问题是如何消除闪烁效果,因此我将只更新更改的单元格。您可以尝试通过向
foreach
循环添加@key
属性来提高渲染性能
您如何进行更新?根据您当前的描述,问题似乎是因为浏览器刷新了整个页面。除了获得一个更快的浏览器(这可能需要升级运行它的计算机)之外,没什么可做的。闪烁不会被消除,只是看不见而已。