2016-01-24 66 views
0

我尝试使用下划线:无法使用下划线模块parse.com

<% if (!_.isEmpty(comments)) { %> 
    <h2>All Comments</h2> 
    <% comments.forEach(function(comment) { %> 
    <% include ../admin/_comment %> 
    <% }) %> 
<% } else { %> 
    <p>No comments yet.</p> 
<% } %> 

我在控制器中添加(这里评论)下面的代码:

var _ = require('cloud/libs/underscore-min'); 

,并在应用程序。 JS

var _ = require('cloud/libs/underscore-min'); 

但我得到这个错误:

_ is not defined 
at eval (eval at <anonymous> (ejs.js:256:12), <anonymous>:31:214) 
at ejs.js:261:15 
at Object.exports.render (ejs.js:299:13) 
at View.exports.renderFile [as engine] (ejs.js:325:22) 
at View.render (express_view.js:77:8) 
at Function.app.render (express_application.js:516:10) 
at res.render (express_response.js:763:7) 
at e.<anonymous> (controllers/gift.js:9:17) 
at e.i (Parse.js:14:27703) 
at e.a.value (Parse.js:14:27063) 

你能帮我吗?

谢谢!

+1

为变量使用另一个名称。 –

回答

0

我已经忘了在main.js补充一点:

app.locals.underscore = underscore; 

,我改名字“_”为“下划线”,得益于弗拉维奥Filho的。