如何调用导出函数(节点.js/续集)
how to call the function for export (node.js / sequelize)
如何调用函数(search_all_user)进行导出(node.js/续集)
module.exports = function (sequelize, Sequelize, DataTypes) {
var User = sequelize.define('user', {
id: {type: Sequelize.INTEGER, unique: true, primaryKey: true, autoIncrement: true},
username: {type: Sequelize.STRING(32), unique: true, allowNull: false},
}, {
classMethods: {
search_all_user: function() {
User.findOne({where: {username: 'coderock'}}).then(function(user){
console.log(user.username);
});
}
}
});
return User;
};
控制器:
model = require('./../models/user.js');
exports.index = function (request, response, next) {
// how to insert function () search_all_user?
response.render('user_signup', {title: 'Регистрация пользователя'});
};
search_all_users
用户模型的类方法中定义。 因此,您可以在需要模型后在控制器中调用它。 下面是一个示例:
var model = require('./../models/user.js');
exports.index = function (request, response, next) {
model.search_all_users.then(...);
};
相关文章:
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 节点.js将变量显示为 HTML
- 如何解决'窗口未定义'终端上的节点JS出错
- S3文件上传文件对象使用节点js
- 在节点 js 中使用护照本地模块验证(登录)密码时出错
- 嵌套的promise节点js
- 使用节点JS发送电子邮件
- 节点JS重定向循环
- 起始节点.js用于并行的线程池
- 获取图像节点js的主色
- 调整节点js中的图像大小
- 节点JS express和控制台输出到命令行与浏览器
- 节点JS:时间机器坏了——timekeeper.travel不做时间旅行
- 如何访问日期并将其插入数据库?节点.JS&MongoDB
- 节点.js快速删除 req.body 不起作用
- 节点.js中的嵌套异步操作
- 如何在核心php应用程序中使用节点js json Web令牌库
- 使用节点js的Bootstrap和Jquery
- 节点.js加密输入/输出类型
- 节点.js在不可能的地方打印“未定义”