Javascript 使用node express从类中呈现方法

Javascript 使用node express从类中呈现方法,javascript,node.js,express,promise,async-await,Javascript,Node.js,Express,Promise,Async Await,我有一个带有方法的类,它应该为我提供API的域。 到目前为止,这也是可行的。但是如果我想用Node Express渲染它,我会得到一个1.2.3的数组。没有域名 我想我的问题出在异步等待 下面是我的类方法的一个片段: class-ISPConfig{ 构造函数(基本url、选项){ this.base\u url=base\u url; this.options=选项; } 异步调用(){ …//给我sessionId } 异步getDataByPrimaryId(ispFunction,pa

我有一个带有方法的类,它应该为我提供API的域。 到目前为止,这也是可行的。但是如果我想用Node Express渲染它,我会得到一个1.2.3的数组。没有域名

我想我的问题出在异步等待

下面是我的类方法的一个片段:

class-ISPConfig{
构造函数(基本url、选项){
this.base\u url=base\u url;
this.options=选项;
}
异步调用(){
…//给我sessionId
}
异步getDataByPrimaryId(ispFunction,param){
试一试{
const results=wait axios.post(this.base_url+isp函数{
会话\u id:等待此操作。\u call(),
主_id:param
});
返回等待结果。数据。响应;
//console.log(结果、数据、响应);
}捕捉(错误){
控制台日志(err);
}

}
尝试将路由设置为异步,例如:

const renderHome = async (req, res) => {
  let domains = [],
      message = '';
  try {
    let a = new ispwrapper.ISPConfig(BASE_URL, OPTIONS)
    const response = await a.getDataByPrimaryId('sites_web_domain_get', { active: 'y' })

    for (let i = 0; i < response.length; i++){
      domains.push(response[i].domain);
    }
  } catch(err) {
    message = 'Error when retriving domains from ISPApi';
  } finally {
    res.render('home', { // 'home' template file for output render
      title: 'ISPConfig',
      heading: 'Welcome to my ISPConfig Dashboard',
      homeActive: true,
      domains,
      message
    });
  }
};
const renderHome=async(req,res)=>{
让域=[],
信息=“”;
试一试{
设a=new ispwrapper.ISPConfig(基本URL,选项)
const response=wait a.getDataByPrimaryId('sites\u web\u domain\u get',{active:'y'})
for(设i=0;i
是的,好的,未定义的不再是问题。但是如何在HTML页面上显示域?调用为灰色


谢谢,这也是我的第一个想法。因为类也是用async/await语法编写的。不幸的是,这在for循环中只给了我3个未定义的值。你能将
响应
结果链接到循环中的一些小东西吗:未定义未定义在循环外:未定义在
响应
中链接d、 没有一个对象具有
domain.domains
属性。在每个对象中
domain
只是一个字符串。请更新答案以反映这一点。请签出