我是Lift的新手,我在Lift中使用bind,Ajax時有問題。Lift框架中的動態綁定
我想用動態的方式創建三個使用Ajax的下拉菜單。我用「Address」作爲例子來描述我試圖達到的目標。在拳頭,我只需要顯示默認設置爲「無」的「國家/地區」菜單。此時用戶可以選擇提交,如果她希望和地址被視爲默認。如果不是,她可以提供確切的地址。一旦她選擇了國家,應該顯示「州」菜單,並且一旦她選擇了「州」,應該顯示「縣」菜單。
在電梯演示示例的幫助下,我嘗試按如下方式創建靜態菜單。我創建了三個片段<select:country/>, <select:state/>, <select:county/>
在我的.html文件和Scala代碼,我綁定如下:
bind("select", xhtml,
"system" -> select(Address.countries.map(s => (s,s)),
Full(country), s => country = s, "onchange" -> ajaxCall(JE.JsRaw("this.value"),s => After(200, replaceCounty(s))).toJsCmd),
"state" -> stateChoice(country) % ("id" -> "state_select"),
"county" -> countyChoice(state) % ("id" -> "county_select"),
"submit" -> submit(?("Go!"),()=>Log.info("Country: "+country+" State: "+state + " County: "+ county)
相應replaceCounty,stateChoice,countyChoice都在我的類中定義。然而,當國家被選中時,只有國家通過阿賈克斯電話而不是縣來刷新。 Q1)有沒有辦法刷新基於國家菜單的菜單? Q2)如何按照前面的解釋動態創建菜單?