我创建了Blazor wasm应用程序。我在那里建立了自己的InputSelect<string>
组件,该组件获得了ID字符串(例如:“ 1,2,3,4,5”)。我解析id显示给他们,可以返回然后转换回一个字符串。如果多重选择菜单已更改,我想用新值更新变量selectedServergroups
。但是我只是在列表中获得了第一个选定的值。如何获得所有选定的值?
@using PhoenixBot.Shared.Instances.Shared
@using PhoenixBot.Client.Helper
@inherits InputSelect<string>
<select class="@CssClass multi-select" @onchange="OnChange" multiple>
@if (Servergroups != null)
{
@foreach (var group in Servergroups)
{
<option value="@Convert.ToInt32(group.Id)" selected="@selectedServergroups.Contains(Convert.ToInt32(group.Id))">@group.Name</option>
}
}
</select>
@code {
[Parameter]
public List<Servergroup> Servergroups { get; set; }
private List<int> selectedServergroups { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
selectedServergroups = GroupHelper.ParseGroupOfString(CurrentValue);
}
private void OnChange(ChangeEventArgs e)
{
Serilog.Log.Error(e.Value.ToString());
}
protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage)
{
result = GroupHelper.ConvertGroupOfList(selectedServergroups);
validationErrorMessage = null;
return true;
}
}
2020-07-09 08:43:38 [ERR] 75
2020-07-09 08:43:40 [ERR] 74
2020-07-09 08:43:41 [ERR] 73
2020-07-09 08:43:43 [ERR] 73
2020-07-09 08:43:45 [ERR] 73