我一直在通过控制器在Strapi代码中添加自定义功能。 下面的结果变量显示为undefined。如果我直接在函数中返回结果变量,则结果将正确返回到http响应中。下面的语法有什么问题吗?感谢您能提供的任何帮助。
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/controllers.html#core-controllers)
* to customize this controller
*/
module.exports = {
async getItemAggregate (context) {
var itemid = context.params.itemid
strapi.log.info(itemid)
strapi.log.info("test aggregate");
const result = await strapi.query('aggregate').findOne({"id": itemid});
strapi.log.info(result)
// const fields = result.toObject();
// strapi.log.info(result)
// entities = await strapi.services.aggregate.search({"id":1});
// entities2 = await strapi.services.item.search({"id":1});
// strapi.log.info(entities)
strapi.log.info(result)
// strapi.log.info(entities2)
//get latest aggregate
//get latest tranacitons
}
};
答案 0 :(得分:0)
遇到了类似的问题。我发现 strapi.log.<function>
不会对查询进行字符串化。尝试记录用 JSON.stringify(<query>)
包装的查询。
像这样:
const result = await strapi.query('aggregate').findOne({"id": itemid});
strapi.log.info(JSON.stringify(result));
答案 1 :(得分:-1)
尝试一下:
const result = await strapi.query('aggregate').findOne({id: itemid});
没有“”作为ID字段