Hello I'm trying to use some javascript built in functions inside jade but I get an error. Here is the code:
- each post in posts
li(class: 'user-') #{post.created} #{post.bo开发者_StackOverflow中文版dy} #{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'
It looks like you mixing tabs and spaces. Jade.js strongly follows the 2 space convention, and tabs ofetn mess up the parser. 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.
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.
精彩评论