【发布时间】:2019-12-29 07:42:22
【问题描述】:
当我在“表单集”中创建新表单时,我想关注新表单。
使用此代码,我得到了想要的结果,但我得到一个“发生未处理的错误”。 Reload' 和控制台中的以下错误:
非常感谢!
<EditForm Model="todos" OnValidSubmit="Save">
<table>
<thead>
<tr>
<th>TODO</th>
</tr>
</thead>
<tbody>
@foreach (var todo in todos)
{
if (todos.IndexOf(todo) != todos.Count - 1)
{
<tr>
<td><input @bind="@todo.Name" /></td>
</tr>
}
if (todos.IndexOf(todo) == todos.Count - 1)
{
<tr>
<td><input @ref="element" @onkeydown="@((KeyboardEventArgs e) => Newline(e))" @bind="@todo.Name" /></td>
</tr>
}
}
</tbody>
</table>
<button class="btn btn-success" type="submit">Save</button>
</EditForm>
在我的代码块中:
ElementReference element;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JSRuntime.InvokeVoidAsync("setFocusOnElement", element);
}
site.js:
function setFocusOnElement(element) {
element.focus();
}
【问题讨论】:
标签: blazor