简体   繁体   English

如何在koa2中显示`[object Promise]`的内容

[英]How to show the content of `[object Promise]` in koa2

Here are my codes 这是我的代码

  let list = ctx.get("list.json");
  ctx.set("Content-Type", "application/json");
            await ctx.render('index', {
                somecontent:onecontent,
                seconddata: list
            });

In index.ejs index.ejs

  <%=seconddata%>

It shows the content [object Promise] , What do I do to show all datas of seconddata ? 它显示内容[object Promise] ,如何显示seconddata所有数据?

Without seeing more of your code... 没有看到更多的代码...

You could try JSON.stringify() 您可以尝试JSON.stringify()

Also, since it looks like list is a Promise object, you might want 另外,由于list看起来像是Promise对象,因此您可能需要

let list = await ctx.get('list.json')

so that list is an array of resolved Promises (which is likely closer to what you want). 因此该list是一组已解决的 Promises(可能更接近您想要的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM