atom feed7 messages in com.googlegroups.liftwebRe: JSON builder
FromSent OnAttachments
MariusApr 5, 2008 2:45 am 
MariusApr 5, 2008 5:54 am 
David PollakApr 5, 2008 5:59 am 
MariusApr 5, 2008 6:06 am 
MariusApr 6, 2008 12:02 am 
David PollakApr 6, 2008 3:11 pm 
MariusApr 6, 2008 10:35 pm 
Subject:Re: JSON builder
From:Marius (mari@gmail.com)
Date:Apr 6, 2008 12:02:29 am
List:com.googlegroups.liftweb

I've re-factored a bit the code a made it accept any JsExp, like:

val json = ("name" -> "Doe") ~ ("phone" -> "1231231231") ~ ("title" -> "Mr.") ~ ("rule" -> AnonFunc(JsReturn(ValById("myField"))))

this yields the following JSon:

{'name' : 'Doe', 'phone' : '1231231231', 'title' : 'Mr.', 'rule' : function() {return document.getElementById('myField').value;}}

JsReturn is not included yet in the lift js layer but I'd like to since it is missing, and currently if we want to return from an anonymous JS function we have to type it manually. JsResponse looks like:

object JsReturn { def apply(in: JsExp): JsExp = JsRaw("return " + in.toJsCmd) }

Thoughts are more than welcomed !