<Divider /> <Suffix> </Suffix> <Divider /> @foreach (var menuGroup in menuItems) { if (menuGroup.Order == -1) { continue; }
<SpaceItem>@menuGroup.Title</SpaceItem> <SpaceItem> @(menuGroup.Children?.Length ?? 0) </SpaceItem> <Row> @foreach (var item in menuGroup.Children) { <TitleTemplate>
@item.Title @item.SubTitle
</TitleTemplate>
} </Row>
} @inject ILocalizationService LocalizationService @inject DemoService demoService @inject IStringLocalizer Localizer; @code{ private string CurrentLanguage => LocalizationService.CurrentCulture.Name; DemoMenuItem[] menuItems = { }; protected override bool ShouldRender() => menuItems.Any(); protected override async Task OnInitializedAsync() { var menu = await demoService.GetMenuAsync(); menuItems = menu.FirstOrDefault(x => x.Url.ToLowerInvariant() == "components")?.Children ?? Array.Empty<DemoMenuItem>(); LocalizationService.LanguageChanged += async (sender, args) => { var menu = await demoService.GetMenuAsync(); menuItems = menu.FirstOrDefault(x => x.Url.ToLowerInvariant() == "components")?.Children ?? Array.Empty<DemoMenuItem>(); await InvokeAsync(StateHasChanged); }; } private async Task OnSearchEnter(string value) { var menu = await demoService.GetMenuAsync(); menuItems = menu.FirstOrDefault(x => x.Url.ToLowerInvariant() == "components")?.Children ?? Array.Empty<DemoMenuItem>(); if (string.IsNullOrWhiteSpace(value)) { return; } IList<DemoMenuItem> result = new List<DemoMenuItem>(); foreach (var item in menuItems.Where(mi => mi.Children != null)) { var lst = item.Children.Where(x => x.Title.Contains(value, StringComparison.OrdinalIgnoreCase)).ToArray(); if (lst.Any()) { result.Add(new DemoMenuItem() { Title = item.Title, SubTitle = item.SubTitle, Order = item.Order, Type = item.Type, Children = lst, }); } } menuItems = result.ToArray(); } }