Jade
Contents
变量的声明和数值的传递
- jade index.jade -P -w –obj ‘{title:”name”}’
- -P:编译后为未压缩的文件
- -w:实时查看编译的结果
- –obj:传入对象
- 如果变量同名文档内的值优先
- jade index.jade -P -w -O jade.json
- -O jade.json:传入json对象
安全转译和非转译
转译
12345- var htmlData="<script>alert(1)</script>"p #{htmlData}p \#{htmlData}p= htmlData<p><script>alert(1)</script></p>非转译
12345- var htmlData="<script>alert(1)</script>"p !{htmlData}p \!{htmlData}p!= htmlData//<p><script>alert(1)</script></p>变量有值时赋变量值无值时变量为空
1234input(value='#{newData}')//<input value="undefined">input(value=newData)//<input>
流程
for
12345- var imooc = {course:'jade',leavel:'high'}- for ( var k in imooc)p= imooc[k]//<p>jade</p>//<p>high</p>each遍历数组
12345- var imooc = {course:'jade',leavel:'high'}- each value,key in imoocp #{value}:#{key}//<p>jade:course</p>//<p>high:leavel</p>嵌套循环
123456-var sections= [{id:1,items:['a','b']},{id:2,items:['a','b']}]dleach section in sectionsdt= section.ideach item in section.itemsdd= item