新手求教:render传递json到前端页面读取不了
代码如下:
db.collection('tblKSection', function (err, collection) {
if (err) {
console.log(err);
} else {
collection.find({}, {_id: 0}).toArray(function (err, docs) {
section = docs;
var timer = setInterval(function () {
if (book && section && knowledge && chapter) {
res.render('addresource', {
knowledge: knowledge,
book: book,
chapter: chapter,
section: section
});
clearInterval(timer);
}
}, 200);
});
}
});
addresource.ejs
<script>
var book = "<%= book %>";
var knowledge = "<%= knowledge %>";
var chapter = "<%= chapter %>";
var section = "<%= section %>";
alert(book);
</script>
输出结果为: [object,object][object,object][object,object] 求指导!!