我很困惑,希望你能帮助我.我正在使用 express.js 在 node.js 中构建一个应用程序,并为我的 ORM 续集.我用以下代码创建了一个模型:
I am confused and I hope you can help me. I am building an app in node.js using express.js and sequelize for my ORM. I have created a model with the following code:
"use strict";
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User", {
username: DataTypes.STRING
});
return User;
};
我的路线是这样的:
router.get('/', function (req, res) {
models.User.findAll({ }).then(function(users) {
res.render('index', {
title: 'Project Insight',
users: users
});
});
})
我正在为我的模板使用 EJS:
And I am using EJS for my templates:
<ul>
<% for(var i=0; i<users.length; i++) {%>
<li><%= users[i] %></li>
<% } %>
</ul>
我在视图中得到的输出是这样的:
The output I getting in my views is this:
[object SequelizeInstance]
[object SequelizeInstance]
[object SequelizeInstance]
[object SequelizeInstance]
我希望能够从数据库中提取名称,但我很困惑为什么会给出这样的结果.如果您需要我提供任何信息,请告诉我.我对这一切都很陌生,我处于停滞状态.提前感谢您的所有帮助.
I want to be able to pull the names from the database and I am confused about why this is giving that result. Please let me know if there is any info you need from me. I am new to all of this and I am at a standstill. Thanks, in advance, for all your help.
尝试更换EJS模板:
<ul>
<% for(var i=0; i<users.length; i++) {%>
<li><%= users[i].username %></li>
<% } %>
</ul>
这篇关于对象 SequelizeInstance 正在传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!