Does doubling the brace escape it? Also you could build the string parts 
outside of the xml and then embed them.

-------------------------------------
Nolan Darilek<no...@thewordnerd.info> wrote:


On 07/28/2009 07:28 PM, David Pollak wrote:
> I'd do the REST API thing.  The mechanisms that Lift has for handling 
> API calls from the browser are numerous, but they are associated with 
> a session (you can do ajaxCall or a S.buildJsonFunc).


Oh cool. When I listened to the podcast interview and heard about 
fast-pathing AJAX calls, I realized that this was exactly what I wanted, 
and that there wasn't a need to create a separate URL space just to 
accomodate this page update functionality--at least, not explicitly in 
the sense of what I meant by "API." Neat. Thanks for the method 
pointers, too, that helped me focus my reading a bit. So here's what I 
have. I have this JS code as an interface to the geolocation API:

function Location() {

   this.lat = 0;
   this.lon = 0;

   this.update = function(lat, lon) {
     this.lat = lat;
     this.lon = lon;
     this.onUpdate(lat, lon);
   };

   this.onUpdate = function(lat, lon) {};
}

var loc = new Location();

Next I wrote a snippet which needs to set loc.onUpdate to a function 
that calls into Lift to update the page. I have:

class Geolocation {

   def updatePosition(pos:String):JsCmd = Alert("Got an update: "+pos)

   def update(in:NodeSeq):NodeSeq = <script type="text/javascript">
     loc.onUpdate = function(lat, lon) {
       {SHtml.ajaxCall(JsObj("lat" -> JsVar("lat"), "lon" -> 
JsVar("lon")), updatePosition _)._2}
     };
</script>
}

Two issues here. First, how do I get those braces around the JS function 
containing the ajaxCall into my HTML? Seems like there should be a way 
to escape braces so I can include them in NodeSeq, but \{ didn't seem to 
do it. I'm also quite new to JS as well, so perhaps there's a better way 
to set that callback. All I can come up with is changing the callback 
signature to accept an object rather than individual values so perhaps I 
can set it directly to the Lift-generated function, but I think I'd 
rather have raw values for individual position components for now.

2. Ideally, I'd like for the JsObj to be an actual Map[String, Float]. 
Is there a way to do this? An included JSON parser that'd convert the 
string to a type I specify, perhaps? (assuming I'd have to give some 
sort of hint for Float vs. other numeric types, anyway)

Thanks. Wow, this really makes AJAX development something I'd actually 
enjoy doing. :)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to