我不能将数据传递到sailsjs到ejs [英] I can't pass data in sailsjs to ejs

查看:283
本文介绍了我不能将数据传递到sailsjs到ejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试SailsJs,但目前从具有4个记录的表中传递Model.count()值,在ejs视图中返回undefined

i'm trying SailsJs but at the moment to pass the Model.count() value from a table with 4 records, in the ejs view returns "undefined"

// SAILS CODE

// SAILS CODE

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 CODE

// EJS CODE

HELLO WORLD! <%= userCount %>

//结果

HELLO WORLD! undefined

// COMMAND LINE CONSOLE.LOG

// COMMAND LINE CONSOLE.LOG

There are 4 users

/ p>

Thank you so much!

推荐答案

也可以写 res.locals.userCount = CountOfUsers; 然后稍后 res.view();

这篇关于我不能将数据传递到sailsjs到ejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆