You could try to use a python code block to generate the array string
(you could even generate it on the controller), perhaps something like
this:
<?python
datasetString = reduce(lambda x,y: str(x) + "," + str(y), bars)
?>
var dataset = [${datasetString}];
The python code (by using the reduce function), will concatenate the
floats inside bars and generate a string like this: "1,2,3,4", then
you just print (output) that string in your javascript code.
You could use standard loop tools in Kid, but quite frankly I don't
see a straight forward way of knowing when you reached the last
element of the list in a loop, perhaps someone more versed in
Kid/Genshi templates could provide some enlightenment here.
Finally there is the way Mengu suggested which could be done with
build-in looping tools, but again I'm not a Genshi/Kid guru and
haven't used it in some time, testing is needed but you get the idea:
var dataset = [];
<py:for="item in bars">
dataset.push(${item});
</py:for>
Regards,
Carlos Ruvalcaba
On Thu, Feb 28, 2013 at 2:07 AM, Mengu <[email protected]> wrote:
> hi,
>
> it's because JavaScript has no idea about your ${bars}. it belongs to
> python. what you should do is instantiating a JS array and then
> looping over your ${bars} and appending its content to JS array.
>
> the following might give you an idea
>
> <script type="text/javascript">
> var dataset = new Array();
> {% for bar in bars %}
> dataset.push(bar);
> {% endfor %}
> </script>
>
> On Feb 27, 2:11 am, vrs762 <[email protected]> wrote:
>> Hi,
>>
>> I have my controller returning an array of floats called arrVals to a kid
>> template file.
>>
>> In the template file within the javascript code block, when I do a <?python
>> print arrVals ?>, I get the right output, which is [0.2, 0.4, 0.6, 0.8]
>>
>> However, when I try assigning arrVals to a javascript variable like this:
>>
>> var dataset[];
>> dataset = "${bars}";
>> alert(dataset);
>>
>> The alert message block shows 0.20.40.60.8, and not as an array.
>>
>> How would I fix this?
>>
>> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/turbogears?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.