javascript 翡翠压痕错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18343651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jade indentation errors
提问by Kivo360
So for my Express site, I'm using jade. So I decided to try modifying my layout file so I can start designing my site. I modified the original layout code (which worked), but I started getting indentation errors in any file that extends layout like this:
所以对于我的 Express 网站,我使用的是 jade。所以我决定尝试修改我的布局文件,以便我可以开始设计我的网站。我修改了原始布局代码(有效),但我开始在任何扩展布局的文件中出现缩进错误,如下所示:
500 Error: /home/kevin/Blue/views/layout.jade:6 4| p Hello World Invalid indentation, you can use tabs or spaces but not both
4| p Hello World
Invalid indentation, you can use tabs or spaces but not both
at Object.Lexer.indent (/home/kevin/Blue/node_modules/jade/lib/lexer.js:679:15)
at Object.Lexer.next (/home/kevin/Blue/node_modules/jade/lib/lexer.js:777:15)
at Object.Lexer.lookahead (/home/kevin/Blue/node_modules/jade/lib/lexer.js:107:46)
at Object.Parser.lookahead (/home/kevin/Blue/node_modules/jade/lib/parser.js:115:23)
at Object.Parser.peek (/home/kevin/Blue/node_modules/jade/lib/parser.js:92:17)
at Object.Parser.tag (/home/kevin/Blue/node_modules/jade/lib/parser.js:640:22)
at Object.Parser.parseTag (/home/kevin/Blue/node_modules/jade/lib/parser.js:624:17)
at Object.Parser.parseExpr (/home/kevin/Blue/node_modules/jade/lib/parser.js:198:21)
at Object.Parser.block (/home/kevin/Blue/node_modules/jade/lib/parser.js:592:25)
at Object.Parser.tag (/home/kevin/Blue/node_modules/jade/lib/parser.js:721:26)
So the code that I have is this:
所以我的代码是这样的:
index.jade
索引.jade
extends layout
block content
p Hello World
and
和
doctype 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
div#header
p This is the header
block content
Keep in mind that I didn't spell anything incorrectly, and I do know how to link together files using the extends option just fine. In fact, the code worked perfectly fine until I started messing with the layout file. All of this is mostly an indention issue. I tried figuring out if it is my text editor causing the problem, and I have been unsuccessful figuring out if it is, as I can't get the code working again.
请记住,我没有拼错任何东西,而且我知道如何使用扩展选项将文件链接在一起就好了。事实上,代码运行得非常好,直到我开始弄乱布局文件。所有这些主要是缩进问题。我试图确定是否是我的文本编辑器导致了问题,但我一直没有成功确定是否是因为我无法让代码再次工作。
I am using the sublime text 2 editor to write this jade code. If it is the text editor not indenting correctly, could somebody help me learn how to fix it?
我正在使用 sublime text 2 编辑器来编写此玉石代码。如果是文本编辑器没有正确缩进,有人可以帮我学习如何修复它吗?
回答by André Dion
In the lower right-hand corner of Sublime Text, there should be a label that says Spaces: N
or Tab Size: N
where N
is a number. Select this and you'll see options to convert the entire document's indentation to use either tabs or spaces:
在 Sublime Text 的右下角,应该有一个标签,上面写着Spaces: N
或Tab Size: N
whereN
是一个数字。选择此项,您将看到将整个文档的缩进转换为使用制表符或空格的选项:
Convert Indentation to Spaces
Convert Indentation to Tabs
Convert Indentation to Spaces
Convert Indentation to Tabs
回答by Rahul Dhiman
for edit form on server.js file set variable like this
用于在 server.js 文件上编辑表单设置变量,如下所示
var applications = row;
res.render("edit", { applications : applications[0] });
for edit.jade file :
对于 edit.jade 文件:
block content
table
thead
tr
th First Name
th Last Name
tbody
- each item in applications
tr
td= item.username
td= item.email
回答by Gabriel Beauchemin-Dauphinais
This answer is an extension to the answer of André Dion (I don't have enough reputation to comment on his post). One can also do the same procedure he described in Visual Studio Code Directly. If you use Pug in Visual Studio Code it will be very nice.
这个答案是对 André Dion 答案的延伸(我没有足够的声誉来评论他的帖子)。也可以直接执行他在 Visual Studio Code 中描述的相同过程。如果你在 Visual Studio Code 中使用 Pug 会非常好。