[英]Blazor table is flicking when updating values
I am using blazor and I have a simple mechanism that send request and gets response(sending 1 request per second).我正在使用 blazor 并且我有一个简单的机制来发送请求并获得响应(每秒发送 1 个请求)。 And that response is mapped by event to such a simple model:
该响应按事件映射到这样一个简单的 model:
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; }
}
And that is send to razor template that looks like:那就是发送到 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>
Well it shows me what I want resp type and it sets it status as css class.好吧,它向我展示了我想要什么类型,并将其状态设置为 css class。 Problem is when response arrive table is flickers on refresh data.
问题是响应到达表在刷新数据时闪烁。
So my question Is how can I remove that flickering effect, so I will update only cell that changes.所以我的问题是如何消除这种闪烁效果,所以我将只更新发生变化的单元格。
You can try and improve the rendering performance by adding a @key
attribute to your foreach
loops.您可以尝试通过在
foreach
循环中添加@key
属性来提高渲染性能。
https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.0#use-key-to-control-the-preservation-of-elements-and-components https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.0#use-key-to-control-the-preservation-of-elements-and-components
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.