2013-08-31 51 views
2

有子菜單的SiteMap定義的several解釋。但它們都依賴於一個菜單定義形式如下:具有Loc定義的Liftweb子菜單

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成爲上面管理菜單的子菜單。這個定義甚至可能嗎?

回答

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而不是純Menu,並指定內部名字先通過它,如Menu("MenuHome", "Home")。顯然你不能這樣做Menu.i(我想沒有人想到它)。

相關問題