Created
August 7, 2012 13:43
-
-
Save kevin4936/3285439 to your computer and use it in GitHub Desktop.
untrustedSelect 多级动态选择
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Area extends Area with LongKeyedMetaMapper[Area] with CRUDify[Long, Area]{ | |
override def dbTableName = "area" | |
} | |
class Area extends LongKeyedMapper[Area] with IdPK{ | |
def getSingleton = Area; | |
object areaId extends MappedLong(this){ | |
override def dbColumnName = "area_id"; | |
} | |
object name extends MappedString(this, 32); | |
object parentId extends MappedLong(this){ | |
override def dbColumnName = "parant_id"; | |
} | |
def findAllByParentId(parentId : Long) = Area.findAll(By(Area.parentId, parentId)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<user:province /> | |
//<user:city /> | |
def register = { | |
var provinceId = "110000"; | |
var cityId = "110100"; | |
def provinceChoice(countryId : Long): Elem = { | |
val provinces = Area.findAllByParentId(countryId); | |
val seq = (provinces.map(area => (area.areaId.toString(), area.name.toString()))).toSeq.asInstanceOf[scala.collection.Seq[(String,String)]]; | |
val (name, js) = SHtml.ajaxCall(JE.JsRaw("this.value"), value => After(200, replaceAreas("city", value.toLong))) | |
SHtml.untrustedSelect(seq, Full(provinces.head.areaId.toString()), provinceId = _, "id" -> "province","style" -> "width:100px;", "onchange" -> js.toJsCmd) | |
} | |
def cityChoice(provinceId : Long): Elem = { | |
val cities = Area.findAllByParentId(provinceId); | |
val seq = (cities.map(area => (area.areaId.toString(), area.name.toString()))).toSeq.asInstanceOf[scala.collection.Seq[(String,String)]]; | |
SHtml.untrustedSelect(seq, Full(cities.head.areaId.toString()), cityId = _, "id" -> "city","style" -> "width:100px;") | |
} | |
def replaceAreas(selectorId : String, parentId : Long): JsCmd = { | |
val areas = Area.findAllByParentId(parentId); | |
val list = (areas.map(area => (area.areaId.toString(), area.name.toString()))).toList.asInstanceOf[List[(String,String)]]; | |
ReplaceOptions(selectorId, list, Full(areas.head.areaId.toString())) | |
} | |
bind("user",registerXHtml,"province" -> provinceChoice(1L), | |
"city" -> (cityChoice(provinceId.toLong)++ SHtml.hidden(() => submitRegister()))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment