How using each under each in jade?

32 views
Skip to first unread message

wan jarus

unread,
Sep 5, 2014, 12:07:17 AM9/5/14
to jad...@googlegroups.com
 

I have my code in Jade-template and using each under each in my code.

resultA = [{no: 1}, {no: 2}, {no: 3}, {no: 4}]
resultB = [{no: 1, name: 'Solo'}, {no: 4, name: 'Polo'}]

thead
  tr
    th No
    th Name
  tbody
    each dataA in resultA
      td #{dataA.no}

      each dataB in resultB
        if dataB.no == dataA.no
          td #{dataB.name}
        else
          td


//run , result

No    Name
1     0
2         0
3             0
4                 0


//But l need like this.

No    Name
1     Solo     
2     
3
4     Polo

What my code wrong?

Thank you.

Forbes Lindesay

unread,
Sep 5, 2014, 6:11:21 AM9/5/14
to jad...@googlegroups.com
Something like:

```jade
- var resultA = [{no: 1}, {no: 2}, {no: 3}, {no: 4}]
- var resultB = [{no: 1, name: 'Solo'}, {no: 4, name: 'Polo'}]

table
  tr
    th No
    th Name
  tbody
    each dataA in resultA
      tr
        td #{dataA.no}
        - var matchingDataB = null;
        each dataB in resultB
          if dataB.no == dataA.no
            - matchingDataB = dataB
        if matchingDataB
          td #{matchingDataB.name}
        else
          td
```

should give you what you’re after


--
You received this message because you are subscribed to the Google Groups "Jade" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jadejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wan jarus

unread,
Sep 7, 2014, 9:50:35 PM9/7/14
to jad...@googlegroups.com
Thank you.
Reply all
Reply to author
Forward
0 new messages