Question

I have a list in a CGI file as follows:

my_list = [apple, oranges, grapes, berries]

I want to iterate through this list in my html code. So far I have this:

<SCRIPT Language="JavaScript">
<!--

document.write('<table border="0" cellspacing="0">')

for(i=0; i <= %d; i++) {
    document.write('<tr height="50">')
    for (j=0; j <3; j++) {document.write('<td width="250" align="center" style="border- top-style:none;border-right-style:none;border-left-style:none;border-bottom- style:solid;border-width:1px;border-color:black;"> '+%s+ '</td>')}
    document.write('</tr>')
}

document.write('</table>')

//-->
</SCRIPT>
...
</html>'''%(len(my_list), my_list)

for each column this prints out apple, oranges, grapes, berries | apple, oranges, grapes, berries and etc.

I want this to print out for the first column

  • apple
  • oranges
  • grapes
  • berries

Then I have another list for the second column and another list for the third column

Était-ce utile?

La solution

It seems like you can do everything in JS once you pass the data in from Python.

If the lists are all the same length here is a plunker for a simplified way of doing that shows how this can be done. http://plnkr.co/edit/0yGwiJXCLQeADL0K7DlJ?p=preview

If the lists can be different sizes I created another plunker to show you how that could be done. http://plnkr.co/edit/jabIJwqvufDaZkX3685D?p=preview

This should be enough to get you started.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top