velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Int64 <vineetbin...@gmail.com>
Subject Re: Velocity Variables are accepted in JavaScript Array??
Date Fri, 12 Jun 2009 02:50:40 GMT

#set($foo = "bar")
suggest.push("$foo")
suggest.push($foo)//Actually this also works.. if i do it like this
$foo="bar"//instead of #set($foo = "bar")

but if $foo=(some value coming from database such as)//$foo=$value//then it
does not work.

i donno why it was behaving like this

Byron Foster-2 wrote:
> 
> Looking at the generated javascript should reveal all. If in Velocity  
> you say
> 
> #set($foo = "bar")
> suggest.push("$foo")
> suggest.push($foo)
> 
> will render as:
> 
> suggest.push("bar")
> suggest.push(bar)
> 
> When the javascript runs the second line is referencing a variable  
> 'bar' which is not defined, and will cause a javascript error.
> 
> If you have the error console running in your browser, you should see  
> javascript errors to this effect.
> 
> On Jun 11, 2009, at 6:24 , Int64 wrote:
> 
>> Your suggestion for suggestions.push("$show"); really worked,
>>
>> But can you please explain why suggestions.push($show);was not  
>> working and
>> it was not working with my values from database(it was working for
>> hard-coded values). and why your suggestion worked??
>>
>> bluejoe-2 wrote:
>>>
>>> if $show is a string, you can try
>>> suggestions.push("$show");
>>>
>>> VTL renders on server-side
>>> while javascript executes on browser
>>>
>>> yours,
>>> bluejoe
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Velocity-Variables-are-accepted-in-JavaScript-Array---tp23956244p23992058.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message