在Blazor服务器端调用StateHasChanged()后,UI不更新

我有这种方法:

function search() {
  // Declare variables
  var input,filter,table,tr,td,i,txtvalue;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("champions");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows,and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[0].getElementsByTagName("img")[0].getattribute("alt");
    console.log(td);
    if (td) {
      //alert(td);
      txtvalue = td;
      if (txtvalue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}

search();

简单来说,每当我单击“提交”按钮时,后者应在调用Input: <input type="text" id="myInput" /> <br/> <table id="champions"> <tr> <td><img id="1" onclick="clicked()" draggable="true" ondragstart="drag(event)" src=".png" alt="1a"></td> </tr> </table>之后变成一个标签,写上“请稍候...”。但是事实并非如此,更改仅在async void TryLogIn() { IsDisabled = true; StateHasChanged(); result = await _LogInService.TryLogIn(logInForm); Console.WriteLine("Logging status : " + (result ? "Sucess" : "Failure")); IsDisabled = false; StateHasChanged(); } 行发生。

我尝试使用StateHasChanged,但我读到使用result = await _LogInService.TryLogIn(logInForm);可能会破坏组件,因此不应使用。

我发现的唯一解决方法是用base.StateHasChanged()BuildRenderTree替换IsDisabled = true行,甚至不必调用await Task.Run(() => { IsDisabled = true; });重新呈现页面。 (与IsDisabled = true; await Task.Delay(1);相同)

我从中得出的唯一结论是,当执行该方法的线程因等待或完成而停止时,页面正在重新呈现自身。

那我想念的是什么?为什么StateHasChanged()没有表现出应有的状态?我不介意使用这些变通办法,但是如果有一个不太粗略的方法,我会考虑的。

bzl789 回答:在Blazor服务器端调用StateHasChanged()后,UI不更新

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3094446.html

大家都在问