小编aru*_*n r的帖子

如何以特定间隔更新动态 DOM 值?

我需要通过使用每秒的计时器来动态更新 DOM 值。

我已经尝试过每秒增加一个计数器值。但是在那个代码中,我只得到了那个 DOM 值的最终值。我需要我的 DOM 中的每一秒值。

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="StartLiveUpdate">Click me</button>

<button class="btn btn-primary" @onclick="StopLiveUpdate">Stop</button>

@code {


    private static System.Timers.Timer syncTimer;
    Random random = new Random();
    void StartLiveUpdate()
    {
        syncTimer = new System.Timers.Timer(1000);

        syncTimer.Elapsed += IncrementCount;
        syncTimer.AutoReset = true;
        syncTimer.Enabled = true;
    }
    void StopLiveUpdate()
    {
        syncTimer.Enabled = false;
        syncTimer.Stop();
    }
    int currentCount = 0;

    void IncrementCount(Object source, System.Timers.ElapsedEventArgs e)
    {
        currentCount++;
        this.StateHasChanged();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core blazor

3
推荐指数
1
解决办法
345
查看次数

如何从 Dart 列表中查找最小值和最大值?

我已经尝试了下面的代码片段,但它会引发有关类型转换的错误,因为列表包含整数和双精度值的组合。但list.reduce(min)仅返回整数值。您能为此提供一个解决方案吗?

注意——但是我只有用户的List。dynamic

final List<dynamic> y = [12, 12, 23.5, 2, 19, 1, 23, 16, 29.7, 32, 45, 68, 23, 21];
List<num> yValues = y;
num yMin = yValues.reduce(min);
num yMax = yValues.reduce(max);
Run Code Online (Sandbox Code Playgroud)

dart

1
推荐指数
1
解决办法
7408
查看次数

标签 统计

asp.net-core ×1

blazor ×1

c# ×1

dart ×1