1

编辑时如何在产品列表中设置选定的值?

<Blazored.Typeahead.BlazoredTypeahead SearchMethod="RicercaCategoria" 
                                      @bind-Value="categoriaSelezionato" 
                                      EnableDropDown="false" 
                                      Placeholder="Scegli o aggiungi la Categoria">
    <SelectedTemplate>@context.NomeCategoria</SelectedTemplate>
    <ResultTemplate>@context.NomeCategoria</ResultTemplate>
</Blazored.Typeahead.BlazoredTypeahead>

从列表中,我可以看到要查看的类别。相反,我从数据库中恢复了我感兴趣的记录

4

1 回答 1

0

你需要设置一个事件来做到这一点。您必须按照文档中的说明稍微修改语法:

将您的 @bind-Value 替换为(猜测类名):

Value="categoriaSelezionato"
ValueChanged="@( (Categoria c) => SelectedCategoriaChanged(c) )"
ValueExpression="@( () => categoriaSelezionato )"

您可能还需要 TValue 和 TItem,但我没有。

然后处理事件:

private void SelectedCategoriaChanged(Categoria categoria )
{
     // Use the selected record however needed


     // Set your Value so it shows:
     categoriaSelezionato = categoria;
}
于 2021-04-28T15:41:01.923 回答