Node.js 中 Jade遍历对象的问题。
报错信息:
读取config.yml:
function read(file){
try {
var doc = yaml.safeLoad(fs.readFileSync(file, 'utf8'));
console.log(doc);
return doc;
} catch (e) {
console.log(e);
}
}
config.yml
db: "mongodb://localhost/blog"
title: "My Blog"
nav:
- 首页: ""
- 目录: ""
- Github: ""
- 关于我: ""
route:
app.get('/', function(req, res, next) {
service.findAll(function(err, data){
if(err){
res.render('db error', err);
}
var _nav = config.read('./config.yml');
var Article = {};
Article.articles = data;//mongodb 的数据
Article.nav = _nav.nav;
res.render('index', Article);
});
});
index.jade:
extends layout
block main
section.container
ul.home.post-list
each item in articles
li.post-list-item
article.post-block
h2.post-title
a.post-title-link(href="post.html") = item.title
.post-meta
.post-time = item.time
.post-content
p = item.content
a.read-more(href="2015/inline-and-absolute/") - 查看更多 -
append scripts
script(src='/plugin/bower_components/jquery/dist/jquery.min.js')
script(src='/javascripts/c.js')
layout.jade:
doctype html
html
head
title= title
meta(charset="utf-8")
meta(http-equiv="X-UA-Compatible", content="IE=edge")
meta(name="description", content="")
meta(name="viewport", content="width=device-width, initial-scale=1")
link(rel='stylesheet', href='/stylesheets/style.css')
block head
body
header
a.logo-link(href="/")
img(src="http://xc66.cc/i/i/xc.jpg")
ul.nav.nav-list
each item in nav
each val, key in item
li.nav-list-item
a.nav-list-link.active(href="#{val}", target="_self") #{key}
block main
block scripts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下一行,缩进!
@hsfzxjy