首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >node.js模块内的循环

node.js模块内的循环
EN

Stack Overflow用户
提问于 2019-05-09 03:24:22
回答 1查看 30关注 0票数 -1

这是我的模块。

代码语言:javascript
复制
module.exports = function (requestUser) {  

  let content = `

    <div id="cpl">
      <table id="currentpatientslists">
      </table>
    </div>
    <div id="rp">
      <h1>Requested Patients</h1>
    </div>
    <hr>    
    <div id="note" >Currently no patients</div>
    <div id="rpl">
    <table id="requestedpatientslists">    
    <tr>
    <td width="30%"></td>
    <td width="30%" class="right"><button>Accept</button></td>
    <td width="30%" class="left"><button>Reject</button></td>
    </tr>
    </table>
    </div>`;

  return render(content);
}

在requestedpatientslists表中,我希望循环来自requestUser的表行中的数据,这是一个数组。我想循环它直到requestUser.length。我该怎么做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-09 03:33:31

您只需要循环遍历用户,并首先为他们创建行

代码语言:javascript
复制
module.exports = function(requestUser) {
  // I'm guessing that the user has normal properties like name, etc?
  const tableRows = requestUser.map(
    user => `
    <tr>
      <td width="30%">${user.name}</td>
      <td width="30%" class="right"><button>Accept</button></td>
      <td width="30%" class="left"><button>Reject</button></td>
    </tr>
  `,
  );
  const content = `

    <div id="cpl">
      <table id="currentpatientslists">
      </table>
    </div>
    <div id="rp">
      <h1>Requested Patients</h1>
    </div>
    <hr>    
    <div id="note" >Currently no patients</div>
    <div id="rpl">
    <table id="requestedpatientslists">    
    ${tableRows.join('\n')}
    </table>
    </div>`;

  return render(content);
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56047729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档