On Thu, Dec 10, 2009 at 12:13 PM, Nolan Darilek <no...@thewordnerd.info>wrote:
> Hello, all. I'm sure this is an incredibly silly mistake on my part, but > I've never really done AJAX until playing with Lift and am at a loss as > to what's going wrong. > > I'm dusting off my old geolocation web app. My current goals are > two-fold: set an initial position based on the browser, then generate > links to update that position based on nearby points. Thus far I have > the first goal working quite nicely. A snippet registers a javascript > callback to call a Lift function, and my page is being updated > correctly. Here's what I have: > > def update(in:NodeSeq):NodeSeq = Script(JsRaw( > """loc.onUpdate = function(lat, lon) { > """+SHtml.jsonCall(JsObj("lat" -> JsVar("lat"), "lon" -> > JsVar("lon")), updatePosition _)._2.toJsCmd+"""; > }""" > )) > > The problem arises when I try calling my updatePosition function from an > SHtml.a link, like so: > > val nodeList = <ul> > {nodes.map(nd => <li>{SHtml.a( > nd.name(None, None).getOrElse("Unnamed way"), > SHtml.jsonCall( > JsObj("lat" -> nd.latitude, "lon" -> nd.longitude), > updatePosition _ > )._2 > )}</li>)} > </ul> > How about: val nodes: List[xxx] = ... val nodeList = nodes match { case Nil => <p>No nodes</p> case xs => <ul>{xs.map(nd => <li>{SHtml.a(() => updatePosition(nd), Text( ns.name(None, None) getOrElse "Unnamed")}</li>)}</ul> > > Ultimately, this function returns a JsCmd that performs two Replaces. > > First, that seems just a bit ugly to me, with the escape within an > escape and all. Is there any way of eliminating that, short of placing > the <ul/> into the template? Ideally this should handle the case where > there are no nearby nodes, in which case there'd be a <p>No nearby > points of interest.</p> instead of the enclosing <ul>, but I haven't > coded that yet. > > Next, clicking on these links doesn't work, and I get a "parent is null" > error from Firebug. I'm guessing that this new call is registered in the > context of a new, blank document, and hence can't perform any of the > Replace commands that work fine when this function is used in the > context of a callback in an existing document? If so, do I need another > Shtml function to make the jsonCall occur in the current DOM? > > Finally, any idea as to why the link names appear as quoted strings > (I.e. "Unnamed way" instead of just Unnamed way)? I'm guessing it may > have to do with the embedded escape, but I'm not entirely certain. > > Thanks in advance, this is such a helpful and patient community, > especially with newbies like myself. :) > > -- > > You received this message because you are subscribed to the Google Groups > "Lift" group. > To post to this group, send email to lift...@googlegroups.com. > To unsubscribe from this group, send email to > liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/liftweb?hl=en. > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@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.