2

带有子菜单的 SiteMap 定义有多种解释。但它们都依赖于这种形式的菜单定义:

Menu.i("Info") / "info" submenus(
  Menu.i("About") / "about" >> Hidden >> LocGroup("bottom"),
  Menu.i("Contact") / "contact",
  Menu.i("Feedback") / "feedback" >> LocGroup("bottom"))

但是,我的菜单定义如下所示:

  val AdminLoginRequired = User.loginFirst
  val sitemap = List(
    Menu(Loc("Home", "index" :: Nil, "Home")),
    Menu(Loc("Admin", "admin" :: Nil, "Admin", AdminLoginRequired, LocGroup("admin")))
  ) ::: Customer.menus ::: User.menus ::: Product.menus

我现在有Product.admin_menus

def viewProductMenuLoc = Full(Menu(Loc("ViewProduct" + menuNameSuffix, viewPath, S.?("view.product"))))

def editProductMenuLoc = Full(Menu(Loc("EditProduct" + menuNameSuffix, editPath, S.?("edit.product"))))

def listProductsMenuLoc = Full(Menu(Loc("ListProducts" + menuNameSuffix, listPath, S.?("list.products"))))

def indexProductsMenuLoc = Full(Menu(Loc("IndexProducts" + menuNameSuffix, indexPath, S.?("index.products"))))

def createProductMenuLoc = Full(Menu(Loc("CreateProduct" + menuNameSuffix, createPath, S.?("create.product"))))

lazy val admin_sitemap: List[Menu] = List(editProductMenuLoc, createProductMenuLoc, indexProductsMenuLoc).flatten(a => a)

我想为admin_sitemap上面的管理菜单创建一个子菜单。这个定义甚至可能吗?

4

1 回答 1

1

我相信您只是将子菜单作为第二个参数传递给 Menu。所以:

val AdminLoginRequired = User.loginFirst
val sitemap = List(
  Menu(Loc("Home", "index" :: Nil, "Home")),
  Menu(
    Loc("Admin", "admin" :: Nil, "Admin", AdminLoginRequired, LocGroup("admin")),
    admin_sitemap: _*
  )
) ::: Customer.menus ::: User.menus ::: Product.menus

但是,您可以将旧的“直接”格式转换为新的 dsl 格式。假设您不需要本地化菜单标签,并且您不关心菜单的内部名称:

val sitemap = List(
  Menu("Home") / "index",
  Menu("Admin" / "admin" >> AdminLoginRequired >> LocGroup("admin") submenus (admin_sitemap: _*)
)) ::: Customer.menus ::: User.menus ::: Product.menus

要使标签可本地化,请使用Menu.i代替 plain Menu,并指定内部名称首先传递它,如Menu("MenuHome", "Home"). 显然你不能这样做Menu.i(我想没有人想到它)。

于 2013-09-09T22:51:48.863 回答