object SequelizeInstance being pass(对象 SequelizeInstance 正在传递)
问题描述
我很困惑,希望你能帮助我.我正在使用 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 正在传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:对象 SequelizeInstance 正在传递


基础教程推荐
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01