jade-for-each-while
if else还是for循环,在jade里面都是可执行的代码
for循环
- var lession = {course:'jade', level:'high'} - for (var k in lession) p= lession[k] => <p>jade</p> <p>high</p>
each
- each value,key in lession p #{key}: #{value} => <p>course: jade</p> <p>level: high</p>
这个each里面的前面-可加可不加
each value,key in lession p #{key}: #{value} => <p>course: jade</p> <p>level: high</p>
除了循环对象,还可以循环数组
- var course = ['node', 'jade', 'express'] - each item in course p= item - for (var item in course) p= course(item) => <p>node</p> <p>jade</p> <p>express</p> <p>node</p> <p>jade</p> <p>express</p>
要用这种in的形式,不能用for(item=0; item<course.lenght; item++)这种
嵌套循环
- var sections = [{id:1,items:['a','b']},{id:2,items:['c','d']}] dl each section in sections dt= section.id each item in section.items dd= item => <dl> <dt>1 <dd>a</dd> <dd>b</dd></dt> <dt>2 <dd>c</dd> <dd>d</dd></dt> </dl>
while
- var n = 0 ul while n<4 li=n++ => <ul> <li>0</li> <li>1</li> <li>2</li> <li>3</li> </ul>