egg-sequelize的查询返回json的问题
我用findAll查询了分类的数据
const list = await model.findAll()
打印list如下:
[
Category {
dataValues: {
id: 1,
name: 'js',
parentId: null,
createdAt: '2020-03-15 12:35:49',
updatedAt: '2020-03-15 12:35:49',
deletedAt: null,
children: [Array]
},
_previousDataValues: {
id: 1,
name: 'js',
parentId: null,
createdAt: '2020-03-15 12:35:49',
updatedAt: '2020-03-15 12:35:49',
deletedAt: null,
children: [Array]
},
_changed: {},
_modelOptions: {
timestamps: true,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: true,
rejectOnEmpty: false,
whereCollection: [Object],
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: [Object],
omitNull: false,
sequelize: [Sequelize],
hooks: {}
},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: [Array],
includeNames: [Array],
includeMap: [Object],
includeValidated: true,
attributes: [Array],
raw: true
},
isNewRecord: false,
children: [ [Category] ]
},
Category {
dataValues: {
id: 3,
name: 'css',
parentId: null,
createdAt: '2020-06-12 01:00:39',
updatedAt: '2020-06-12 01:00:39',
deletedAt: null,
children: []
},
_previousDataValues: {
id: 3,
name: 'css',
parentId: null,
createdAt: '2020-06-12 01:00:39',
updatedAt: '2020-06-12 01:00:39',
deletedAt: null,
children: []
},
_changed: {},
_modelOptions: {
timestamps: true,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: true,
rejectOnEmpty: false,
whereCollection: [Object],
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: [Object],
omitNull: false,
sequelize: [Sequelize],
hooks: {}
},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: [Array],
includeNames: [Array],
includeMap: [Object],
includeValidated: true,
attributes: [Array],
raw: true
},
isNewRecord: false,
children: []
}
]
然后我把list给ctx.body
返回
ctx.body = list
打印的response中,list是正确的json,而不是上面的对象,json如下:
\[
{
"id": 1,
"name": "js",
"parentId": null,
"createdAt": "2020-03-15 12:35:49",
"updatedAt": "2020-03-15 12:35:49",
"deletedAt": null,
"children": \[
{
"id": 2,
"name": "ts",
"parentId": 1,
"createdAt": "2020-06-12 01:00:29",
"updatedAt": "2020-06-12 01:00:29",
"deletedAt": null,
"children": \[\],
"articles": \[\]
}
\]
},
{
"id": 3,
"name": "css",
"parentId": null,
"createdAt": "2020-06-12 01:00:39",
"updatedAt": "2020-06-12 01:00:39",
"deletedAt": null,
"children": \[\]
}
\]
为什么会不一样呢?还是sequelize对这个封装对象做了什么处理?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论