从数据库获取数据时运行/隐藏微调器加载
我正在从大数据库获取数据,第一个查询大约需要 10-12 秒才能使用网格视图获取数据 - 我正在将 Blazer 与实体一起使用。
我想在加载数据时显示微调器,并且一旦获取所有数据,微调器就应该停止或隐藏。无论旋转器的位置如何。
这是我的 CSS:
.loader {
display: none;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
}
.loading {
border: 2px solid #ccc;
width: 60px;
height: 60px;
border-radius: 50%;
border-top-color: #1ecd97;
border-left-color: #1ecd97;
animation: spin 1s infinite ease-in;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
这是我的 js 函数:
spinner: function(){
document.getElementsByClassName("loader")[0].style.display = "block";
HTML :
<div class="col-auto offset-5">
<button class="btn btn-info " @onclick="GetTags" style="width: 175px;">Get Tags</button>
<div class="loader">
<div class="loading">
</div>
</div>
</div>
这是我的 blazor 方法,它从数据库获取数据并调用 js 方法“spinner”
public async Task GetTags()
{
await JSRuntime.InvokeVoidAsync("myMap.spinner");
AllTags = await Task.Run(() => tagsService.Map(InputRadius, SelectedTimeDate, Long, Lat));
}
当前结果是当我单击 GetTags 按钮时按钮转换的结果即使数据已完全收集,旋转器仍会加载。
我确实相信我做错了什么,但我不知道那是什么。
有什么提示吗?
I'm getting data from big database which the first query takes around 10-12 seconds to get my data using grid view - I'm using Blazer with entity.
I would like to display the spinner when I'm loading the data and once all the data get fetched the spinner should be stopped or hided. No mater the location of the spinner.
This is my CSS:
.loader {
display: none;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
}
.loading {
border: 2px solid #ccc;
width: 60px;
height: 60px;
border-radius: 50%;
border-top-color: #1ecd97;
border-left-color: #1ecd97;
animation: spin 1s infinite ease-in;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
this is my js function:
spinner: function(){
document.getElementsByClassName("loader")[0].style.display = "block";
HTML :
<div class="col-auto offset-5">
<button class="btn btn-info " @onclick="GetTags" style="width: 175px;">Get Tags</button>
<div class="loader">
<div class="loading">
</div>
</div>
</div>
and this is my blazor method that gets the data from the database and call the js method 'spinner'
public async Task GetTags()
{
await JSRuntime.InvokeVoidAsync("myMap.spinner");
AllTags = await Task.Run(() => tagsService.Map(InputRadius, SelectedTimeDate, Long, Lat));
}
The current result is when I'm clicking on the GetTags button the button converted to spinner and still loading even if the data fully gathered.
I do believe that I'm doing something wrong but i don't know what it is.
Any hint ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您首先需要更新 JavaScript 以包含
hide
和show
函数,或者包含一个parameter
来指示哪个函数。我还建议使用
querySelector
而不是getElementsByClassName
,因为您想使用唯一或第一个.loader
元素。然后在您的 Blazor 代码中:
You will first need to update your JavaScript to contain a
hide
and ashow
function, or include aparameter
to indicate which.I also suggest using
querySelector
instead ofgetElementsByClassName
, since you want to work with the only or first.loader
element.Then in your Blazor code: