[英]javascript in jade
Hello I'm trying to use some javascript built in functions inside jade but I get an error. 您好,我尝试在玉器中使用一些内置的javascript函数,但出现错误。 Here is the code:
这是代码:
- each post in posts
li(class: 'user-') #{post.created} #{post.body} #{post.title} #{post.tags} #{post._id}
- var tags = post.tags
- tags.split(' ')
- each tag in tags
li(class : 'tags') #{tags.tag}
I get the error : Object tag1,,,,,,,,tag2 has no method 'split'
我收到错误消息:
Object tag1,,,,,,,,tag2 has no method 'split'
It looks like you mixing tabs and spaces. 好像您混合了制表符和空格。 Jade.js strongly follows the 2 space convention, and tabs ofetn mess up the parser.
Jade.js严格遵循2空间约定,并且选项卡将解析器弄乱了。 Removing the tabs everything works fine for me.
删除标签对我来说一切正常。
- each post in posts
li(class: 'user-') #{post.created} #{post.body} #{post.title} #{post.tags} #{post._id}
- var tags = post.tags.split(' ')
- each tag in tags
li(class : 'tags') #{tags.tag}
And the Javascript to render the .jade file. 以及呈现.jade文件的Javascript。
var jade = require('jade');
var options = {
locals: {
posts:[{
created:'today',
tags:'1 2 3'
}]
}
};
jade.renderFile(__dirname + '/each.jade', options, function(err, html){
if (err) throw err;
console.log(html);
});
Just make sure you are passing in a tags
variable to the local variables. 只需确保将
tags
变量传递给局部变量即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.