我正在尝试 SailsJs,但目前要从包含 4 条记录的表传递 Model.count() 值,在 ejs View 中返回“未定义”
// sails 代码
module.exports = {
create:function(req,res){
CountOfUsers=User.count().exec(function (error, found){console.log('There are ' + found + ' users');});
return res.view('privacy', {
userCount: CountOfUsers
});
}};
//EJS 代码
HELLO WORLD! <%= userCount %>
//结果
HELLO WORLD! undefined
//命令行控制台.LOG
There are 4 users
非常感谢!
最佳答案
也可以写成 res.locals.userCount = CountOfUsers;
,然后再写成 res.view();
关于javascript - 我无法将 sailsjs 中的数据传递给 ejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26599968/