2014-05-20 64 views
0

我試圖運行以下jade文件並面臨錯誤。可一些幫助,請嘗試運行jade文件時出錯:for循環

extends layout 
block content 
    h1. 
     Electronics 
    div.left 
     p Televisions 


     -for(var i=0; i<10; ++i) 
     { 

     div.nameprod Name of TV : 
     for item in tryCSS 
      li 
       a=item.description + item.type 
     div.nameprod Company Name : 
     for item in tryCSS  
      li 
       a= item.brand 
     div.nameprod Size of TV : 
     for item in tryCSS 
      li 
       a= item.size 
     div.nameprod Color of TV : 
     for item in tryCSS 
      li 
       a= item.color 
     div.nameprod Features in TV : 
     for item in tryCSS 
      li 
       a= item.price 
     } 

我收到以下錯誤 請幫

C:\node\nodetest1\views\tryCSS.jade:11 9| 10| -for(var i=0; i<10; ++i) > 11| { 12| 13| div.nameprod Name of TV : 14| for item in tryCSS unexpected text { 

Error: C:\node\nodetest1\views\tryCSS.jade:11 
9|   
10|   -for(var i=0; i<10; ++i) 

11 | { 12 |
13 | div.nameprod電視名稱: 14 |在tryCSS

項目
unexpected text { 

at Object.Lexer.fail (C:\node\nodetest1\node_modules\jade\lib\lexer.js:816:11) 
at Object.Lexer.next (C:\node\nodetest1\node_modules\jade\lib\lexer.js:875:15) 
at Object.Lexer.lookahead (C:\node\nodetest1\node_modules\jade\lib\lexer.js:113:46) 
at Parser.lookahead (C:\node\nodetest1\node_modules\jade\lib\parser.js:100:23) 
at Parser.peek (C:\node\nodetest1\node_modules\jade\lib\parser.js:77:17) 
at Parser.block (C:\node\nodetest1\node_modules\jade\lib\parser.js:685:30) 
at Parser.tag (C:\node\nodetest1\node_modules\jade\lib\parser.js:800:26) 
at Parser.parseTag (C:\node\nodetest1\node_modules\jade\lib\parser.js:719:17) 
at Parser.parseExpr (C:\node\nodetest1\node_modules\jade\lib\parser.js:188:21) 
at Parser.block (C:\node\nodetest1\node_modules\jade\lib\parser.js:689:25) 

我下面

玉文件圖像[1]:http://i.stack.imgur.com/YqCcx.gif

回答

1

玉使用縮進塊,不花括號,即使是JavaScript的循環。您應該相應地修改您的代碼:

extends layout 
block content 
    h1. 
     Electronics 
    div.left 
     p Televisions 
     -for(var i=0; i<10; ++i) 
      div.nameprod Name of TV : 
      for item in tryCSS 
       li 
        a=item.description + item.type 
      div.nameprod Company Name : 
      for item in tryCSS  
       li 
        a= item.brand 
      div.nameprod Size of TV : 
      for item in tryCSS 
       li 
        a= item.size 
      div.nameprod Color of TV : 
      for item in tryCSS 
       li 
        a= item.color 
      div.nameprod Features in TV : 
      for item in tryCSS 
       li 
        a= item.price