我需要选择我想要的制造商,然后在此之后,我需要检索的某些制造商所需的所有型号。
@if (manufacturersRetrieved)
{
<MudTextField T="string" Label="Filter Manufacturer" Variant="Variant.Outlined" @bind-Value="manufacturerFilter" @oninput="ApplyManufacturerFilter"></MudTextField>
<MudSelect T="ManufacturerDto" @bind-Value="selectedManufacturer" Label="Select desired Manufacturer" Search="true" Variant="Variant.Outlined">
@foreach (var option in filteredManufacturers)
{
<MudSelectItem T="ManufacturerDto" OnClick="() => RetrieveModels(option.ManufacturerId)" Value="@option">@option.ManufacturerName</MudSelectItem>
}
</MudSelect>
<MudButton Class="ma-1" Variant="Variant.Filled" Color="Color.Secondary" OnClick="GetManufacturers">Get All Manufacturers</MudButton>
@if (modelsRetrieved)
{
@if (filteredModels == null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true"/>
}
else
{
<MudTextField T="string" Label="Filter Model" Variant="Variant.Outlined" @bind-Value="modelFilter" @oninput="ApplyModelFilter"></MudTextField>
<MudSelect T="ModelDto" Label="Select desired Model" @bind-Value="selectedModel" Search="true" Variant="Variant.Outlined">
<Content>
@foreach (var option in filteredModels)
{
<MudSelectItem T="ModelDto" Value="@option">@option.ModelName</MudSelectItem>
}
</Content>
</MudSelect>
}
}
}
@code {
private IEnumerable<ManufacturerDto> manufacturers = new List<ManufacturerDto>();
private IEnumerable<ManufacturerDto> filteredManufacturers = new List<ManufacturerDto>();
private IEnumerable<ModelDto> models = new List<ModelDto>();
private IEnumerable<ModelDto> filteredModels = new List<ModelDto>();
private string manufacturerFilter = "";
private string modelFilter = "";
private bool manufacturersRetrieved = false;
private bool modelsRetrieved = false;
private ManufacturerDto selectedManufacturer = null;
private ModelDto selectedModel = null;
protected override void OnInitialized()
{
manufacturers = _iDataService.GetManufacturersFromLocalData().OrderBy(x => x.ManufacturerName);
manufacturersRetrieved = true;
ApplyManufacturerFilter(null);
}
private void ApplyManufacturerFilter(ChangeEventArgs e)
{
filteredManufacturers = manufacturers.Where(x => x.ManufacturerName.ToLower().Contains(manufacturerFilter.ToLower()));
}
private async Task GetManufacturers()
{
manufacturers = await _iCarService.GetManufacturersFromApi();
filteredManufacturers = manufacturers.OrderBy(x => x.ManufacturerName).Where(x => x.ManufacturerName.ToLower().Contains(manufacturerFilter.ToLower()));
}
private async Task RetrieveModels(long manufacturerId)
{
models = (await _iCarService.GetModelsOnManufacturerId(manufacturerId)).OrderBy(x => x.ModelName).ToList();
modelsRetrieved = true;
ApplyModelFilter(null);
}
private void ApplyModelFilter(ChangeEventArgs e)
{
modelFilter = e.Value.ToString();
filteredModels = models.Where(x => x.ModelName.ToLower().Contains(modelFilter.ToLower()));
}
}
我不能解决这个问题。我需要这样做。
我试过很多方法,但这一种似乎是最有效的。
我试着在MudSelect
中创建OnClose
,但它不够好。我甚至试着把所有东西都列成按钮,但没有。
1条答案
按热度按时间sirbozc51#
试试这个