Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I iterate a multi-dimensional array with Jade template lang

Tags:

node.js

pug

I'm wondering if it is possible to iterate a multi-dimensional array, in Node.js I'm returning an array that has an object inside of it, and I'm putting it into an array so that I can push to it, but when it is all done pushing, I'm left with something like

[ [
   {
     stuff: stuff
   }
  ],
  [ 
   { 
    stuff: stuff
   }
  ]
]

I tried

each item in items
  p= item

which returns [object Object]

When I try

each item in items
  p= item.invdescription

I get an error, any idea how I can do such a thing with Jade? Thanks!

Basically:

for (var i = 0; i < items.length; i += 1) {
  p= items[0][i].invdescription
}
like image 722
Datsik Avatar asked May 11 '13 20:05

Datsik


1 Answers

if items is having the value

[ [
   {
     stuff: stuff
   }
  ],
  [ 
   { 
    stuff: stuff
   }
  ]
]

then you can iterate over the stuff values in jade via

each item in items
     p #{item[0].stuff}
like image 179
Mithun Satheesh Avatar answered Oct 16 '22 04:10

Mithun Satheesh