編輯:我只是意識到我的問題不是這個例子不起作用!這是該頁面不出現在菜單中!另外,我如何處理沒有參數的頁面?在電梯中,改變Menu.param的行爲方式
我很難找到Menu.param的通用定義。 Simply Lift中有這樣的例子,並且在這個論壇中有一些代碼的引用,但是這個特性非常重要,儘管我可以告訴它,但它並沒有很好的記錄。
現在,我的網站地圖出現問題。我在sitema Boot.scala和代碼中聲明的任何東西似乎都被接受,但卻被忽略。 localhost:8080/journal會導致404,並且菜單項「Autobiography」不會出現在站點地圖中。
所以,一方面,這篇文章是對這段代碼的幫助。爲什麼會被忽略? (同樣,它編譯並執行時沒有錯誤。)
另一方面,它只是我還是「參數」在大衛波拉克的例子之外沒有記錄?它不在API中:http://main.scala-tools.org/ mvnsites/liftweb-2.0/framework/scaladocs/net/liftweb/sitemap/Menu $ object。html。
謝謝。
這是我的網站地圖。我添加了來自Simply Lift的Param示例,以查看它是否有效。它沒有。
def sitemap = SiteMap(
Menu.i("Home")/"index" >> User.AddUserMenusAfter, // the simple way to declare a menu
Menu.i("Artifact")/"artifact", // Works
// Menu.i("Autobiography")/"journal", // Works if I comment out the next line.
AutobiographyPageMenu.menu,
Menu.param[AutobiographyPage]("Autobiography2", "Autobiography2", // Similar code as previous line. Doesn't work.
pageName => Full(AutobiographyPage(pageName)),
ap => ap.pageName)/"journal2",
Param.menu, // Added to see if D. Pollack's code would work. It didn't.
// more complex because this menu allows anything in the
// /static path to be visible
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))
這是它從代碼段子包中的文件引用的代碼。電梯可以找到類:它不抱怨他們沒有被定義。
case class AutobiographyPage(pageName: String)
object AutobiographyPageMenu {
val menu = Menu.param[AutobiographyPage]("Autobiography", "Autobiography",
pageName => Full(AutobiographyPage(pageName)),
ap => ap.pageName)/"journal"
// I'm not sure what these two lines are for...
lazy val loc = menu.toLoc
def render = "*" #> loc.currentValue.map(_.pageName)
}
// This code is copied from the Simply Lift book:
// capture the page parameter information
case class ParamInfo(theParam: String)
// a snippet that takes the page parameter information
class ShowParam(pi: ParamInfo) {
def render = "*" #> pi.theParam
}
object Param {
// Create a menu for /param/somedata
val menu = Menu.param[ParamInfo]("Param", "Param",
s => Full(ParamInfo(s)),
pi => pi.theParam)/"param"
lazy val loc = menu.toLoc
def render = "*" #> loc.currentValue.map(_.theParam)
}
我剛剛意識到我的問題不是該示例不起作用!這是該頁面不出現在菜單中!另外,我如何處理沒有參數的頁面? – eje211 2012-03-23 18:32:54