首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Blazorise选择默认值

Blazorise选择默认值
EN

Stack Overflow用户
提问于 2020-05-21 23:00:21
回答 1查看 873关注 0票数 2

有没有办法使用Blazorise中的从列表中选择默认值?现在默认值是null,但我希望它是"3“。

代码语言:javascript
复制
<Select @bind-SelectedValue="@_someProperty">

                                @foreach (string number in _numbers)
                                    {
                                    <SelectItem Value="@number ">@number </SelectItem>
                                    }
                            </Select>

@code
private static readonly string[] _numbers =
        {
            "1", "2", "3", "4", "5",
        };
EN

回答 1

Stack Overflow用户

发布于 2020-06-14 01:23:39

这是一个解决这个问题的简单方法(只需添加一个具有初始值的变量)。您还可以使用SelectedValueChanged手动处理您的自定义变量。

代码语言:javascript
复制
<Select @bind-SelectedValue="@_selectedProperty" SelectedValueChanged="@OnSelectedValueChanged">

                                @foreach (string number in _numbers)
                                    {
                                    <SelectItem Value="@number ">@number </SelectItem>
                                    }
                            </Select>

@code
{

private string _selectedProperty = 3;
private static readonly string[] _numbers =
        {
            "1", "2", "3", "4", "5",
        };

void OnSelectedValueChanged( string value )
{
    _selectedProperty = value; // Bind to the custom variable
    Console.WriteLine( selectedValue ); // Write in Console Just for Checking
}

}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61937418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档