JSON Samples



Here's the code:

class Json {
  object json extends JsonHandler {
    def apply(in: Any): JsCmd =
    SetHtml("json_result", in match {
        case JsonCmd("show", _, p: String, _) => Text(p)
        case JsonCmd("textile", _, p: String, _) =>
          TextileParser.toHtml(p, Empty)
        case JsonCmd("count", _, p: String, _) => Text(p.length+" Characters")
        case x => <b>Problem... didn't handle JSON message {x}</b>
      })
  }

  def sample(in: NodeSeq): NodeSeq =
  bind("json", in,
       "script" -> Script(json.jsCmd),
       AttrBindParam("onclick",
                     Text(json.call(ElemById("json_select")~>Value,
                                    ElemById("json_question")~>Value).toJsCmd),
                     "onclick"))
}