JsObj - escaping Strings when output to page

23 views
Skip to first unread message

Bufferine

unread,
Dec 8, 2010, 9:33:08 PM12/8/10
to Lift
Hi,

What am I doing wrong? I'm trying to output a javascript object into
the page (so my front end guy can do some stuff with the data without
parsing it out of elements by id) but it's replacing all the double
quotes with " (only in view source - if I inspect it then firebug
converts them to double quotes again)

I've copied the example from Exploring Lift, but it still does the
same:

& ".data_as_object *" #> {
JsCrVar("myObject", JsObj(("persons", JsArray(
JsObj(("name", "Thor"), ("race", "Asgard")),
JsObj(("name", "Todd"), ("race", "Wraith")),
JsObj(("name", "Rodney"), ("race", "Human"))
))))

becomes

<div class="data_as_object" style="display: none;">var myObject =
{&quot;persons&quot;: [{&quot;name&quot;: &quot;Thor&quot;,
&quot;race&quot;: &quot;Asgard&quot;}, {&quot;name&quot;:
&quot;Todd&quot;, &quot;race&quot;: &quot;Wraith&quot;},
{&quot;name&quot;: &quot;Rodney&quot;, &quot;race&quot;:
&quot;Human&quot;}]
};</div>


I've noticed that if what I'm outputting is a number rather than a
string then it's fine.

I'm running Scala 2.8.1 and Lift 2.2RC1 - it's a normal templated SBT
project from the archetype.

Catherine

David Pollak

unread,
Dec 8, 2010, 10:36:40 PM12/8/10
to lif...@googlegroups.com
On Wed, Dec 8, 2010 at 6:33 PM, Bufferine <catheri...@gmail.com> wrote:
Hi,

What am I doing wrong? I'm trying to output a javascript object into
the page (so my front end guy can do some stuff with the data without
parsing it out of elements by id) but it's replacing all the double
quotes with &quot; (only in view source - if I inspect it then firebug
converts them to double quotes again)
Try:

& ".data_as_object *" #> {
   Script(JsCrVar("myObject", JsObj(("persons", JsArray(

       JsObj(("name", "Thor"), ("race", "Asgard")),
       JsObj(("name", "Todd"), ("race", "Wraith")),
       JsObj(("name", "Rodney"), ("race", "Human"))
   )))))

JsExp are also Nodes, so they render out, but they render out escaped.  Putting Script() around them turns them into:
<script>
// <![CDATA[
....
]]>
</script>

Which is what you want.

 

I've copied the example from Exploring Lift, but it still does the
same:

& ".data_as_object *" #> {
   JsCrVar("myObject", JsObj(("persons", JsArray(
       JsObj(("name", "Thor"), ("race", "Asgard")),
       JsObj(("name", "Todd"), ("race", "Wraith")),
       JsObj(("name", "Rodney"), ("race", "Human"))
   ))))

becomes

<div class="data_as_object" style="display: none;">var myObject =
{&quot;persons&quot;: [{&quot;name&quot;: &quot;Thor&quot;,
&quot;race&quot;: &quot;Asgard&quot;}, {&quot;name&quot;:
&quot;Todd&quot;, &quot;race&quot;: &quot;Wraith&quot;},
{&quot;name&quot;: &quot;Rodney&quot;, &quot;race&quot;:
&quot;Human&quot;}]
};</div>


I've noticed that if what I'm outputting is a number rather than a
string then it's fine.

I'm running Scala 2.8.1 and Lift 2.2RC1 - it's a normal templated SBT
project from the archetype.

Catherine

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@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
Blog: http://goodstuff.im
Surf the harmonics

Catherine Jung

unread,
Dec 9, 2010, 12:24:53 AM12/9/10
to lif...@googlegroups.com
Ahh - that does it, perfect, thanks.

Catherine

Reply all
Reply to author
Forward
0 new messages