0

I'm trying to do something like the following (stripped of optimization for demonstration purposes):

table
    - for(j = 0; j < 10; j++)
    tr
        td Name
        td -for(i = 0; i < 10; i++) // Output a a letter from an array
            #{data[i] + list[i][j]}
            - if(j < list[i].length) // Add a comma if it isn't the last element
            ,

The idea is that the second td will contain a list of comma-separated values, and the if statement will check if it's the last one - if not, add the comma. I'm sure it's more so just my amateur understanding of Jade that's making this feel impossible. Seems like I can't quite get the value in the right place for the td - because of my indentation, it makes a new tag with a name of data[i] + list[i][j] which actually seems like the right thing for Jade to do, but I just can't see how else to accomplish this and Jade documentation is scarce.

4

2 回答 2

0

Try:

table
    - for(var j = 0; j < 10; j++)
      tr
          td Name
          - for(var i = 0; i < 10; i++)
            td #{data[i] + list[i][j]}
            - if(j < list[i].length)
              ,

I have not tested directly your code, but simpler version which worked as expected. Hope it's what you need.

于 2012-11-23T21:57:18.660 回答
0

I was able to forge a solution with some experimentation after an answer by dreame4 - basically I realized that I didn't need a tag, and that Jade was interpeting my #{ data[i]} segment as a tag. Using a pipe (|) I just told Jade not to interpet it as a tag:

table
    - for(j = 0; j < 10; j++)
    tr
        td Name
        td 
            -for(i = 0; i < 10; i++) // Output a a letter from an array
            | #{data[i] + list[i][j]}
            - if(j < list[i].length) // Add a comma if it isn't the last element
            ,
于 2012-11-23T23:51:41.120 回答