这可能是一个愚蠢的问题。但我试图阅读更多有关 Blazor 的内容,但我总是对@code
. 据我了解,当您@code
在客户端 blazor 内部使用时,所有内容都在客户端浏览器本地运行。所以我有几个问题:
@code
在服务器上运行还是在客户端上运行?@code
本质上是在blazor中转换为JS吗?我正在使用 Blazor 服务器端。
我有几个绑定到不同值的输入框,但是只要有输入,它们就必须调用相同的函数。该函数本质上会启动计时器,该计时器旨在在经过 X 时间后保存数据。
Summary: <input class="summary-input @Utilities.SummaryWarning" type="text" @ref="Utilities.CreateSummaryRef" placeholder="Describe summary of an issue." @bind="Utilities.CurrentlyViewedProblem.SummaryText" @oninput="RestartSaveTimer">
Run Code Online (Sandbox Code Playgroud)
我的问题是,使用此代码,输入框的行为不像oninput
,而是更多的onchange
. 在框失去焦点之前,不会绑定该值。但是每次击键都会启动计时器。所以我想要的结果是在击键时绑定值,并在击键时启动计时器。
我能想到的唯一方法是为每个将手动更新值的框创建单独的 RestartSaveTimer 方法,但在我的情况下,这是不希望的,因为输入框是根据数据大小动态填充的。
我试着添加@bind:event="oninput"
它。但它抱怨oninput
使用了两次或更多次。
请记住,我有多个这些行bind
绑定到不同的属性,但它们都必须调用相同的RestartSaveTimer
编辑
所以其他框由 for 循环填充
@foreach (Solution solution in Utilities.CurrentlyViewedProblem.SolutionsList)
{
<div class= "solution">
<textarea class="solution-input" placeholder="Describe solution to an issue." @bind="solution.SolutionText" @oninput="((ChangeEventArgs e) => CheckSolutionRestartTimer(e, solution))"></textarea>
<div class="vote">
<button class="vote-button" @onclick="@(() => IncrementVote(solution))"></button>
<div class="vote-label">@solution.Votes</div>
</div>
</div>
<div class="date-box-solution">
<div class="date-created"> Created on: …
Run Code Online (Sandbox Code Playgroud)