gpt4 book ai didi

c# - 如何在 Serenity 中创建动态菜单?

转载 作者:太空宇宙 更新时间:2023-11-03 12:24:04 24 4
gpt4 key购买 nike

我正在尝试为仪表板制作一个动态菜单,我有一个仪表板寄存器,其中只有描述和链接。注册后,它必须出现在菜单中。

我的新菜单页面将包含一个框架,用于在新页面中打开此链接。

有没有一种简单的方法可以在 serenity 中更改菜单以具有这种行为?

enter image description here

enter image description here

最佳答案

我已经改变了 NavigationModel.cs

经过大量搜索,没有找到这样做的例子。

我创建了一个像这样的 DynamicNavigation:

 public class DynamicDashboards : INavigationItemSource
{
public List<NavigationItemAttribute> GetItems()
{
var items = new List<NavigationItemAttribute>
{
new NavigationMenuAttribute(1000, "Dashboards", "icon-speedometer")
};

using (var connection = SqlConnections.NewByKey("Default"))
{
var dashboards = connection.List<DashboardsRow>();
foreach (var dashboard in dashboards)
items.Add(new NavigationLinkAttribute(1000,
path: "Dashboards/" + dashboard.Descricao.Replace("/", "//"),
url: "~/Dashboards/DefaultDashboard?link=" + dashboard.Link,
permission: CadastrosPermissionKeys.General,
icon: "icon-speedometer"));
}

return items;
}
}

它们在 NavigationModel.cs 上,我正在调用此类以将其插入到 Items

    var dy = new DynamicDashboards();
var dashboardMenu = NavigationHelper.ConvertToNavigationItems(NavigationHelper.ByCategory(dy.GetItems()), x => x != null && x.StartsWith("~/") ? VirtualPathUtility.ToAbsolute(x) : x);
Items[0] = dashboardMenu[0]

在我的例子中,我在 Dashboard 中有一个默认菜单,所以我只是在位置 [0] 上再次添加它,您可以随意操作它。

关于c# - 如何在 Serenity 中创建动态菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45921013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com