Node.js 将表单选择框从.pug转换为.ejs

Node.js 将表单选择框从.pug转换为.ejs,node.js,pug,ejs,Node.js,Pug,Ejs,我正在尝试将下面的内容从哈巴狗转换为ejs。它是一个从表单中的关联集合中选择作者的框,用于将书籍添加到数据库中。当我添加一本新书时,它抛出了一个错误:无法读取指向第一个选项元素的未定义属性“\u id”,但由于某种原因,我可以更新一本现有的书。在帕格版本中,它不会抛出这个错误。我的转换正确吗 select#author.form-control(type='select', placeholder='Select author' name='author' required='true' )

我正在尝试将下面的内容从哈巴狗转换为ejs。它是一个从表单中的关联集合中选择作者的框,用于将书籍添加到数据库中。当我添加一本新书时,它抛出了一个错误:无法读取指向第一个选项元素的未定义属性“\u id”,但由于某种原因,我可以更新一本现有的书。在帕格版本中,它不会抛出这个错误。我的转换正确吗

select#author.form-control(type='select', placeholder='Select author' name='author' required='true' )
  - authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;});
  for author in authors
    if book
      option(value=author._id selected=(author._id.toString()==book.author._id.toString() ? 'selected' : false) ) #{author.name}
    else
      option(value=author._id) #{author.name}
我的转换:

<select class="form-control" id="author" type="select" placeholder="Select author" name="author" required="true">
  <% authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;}); %>
  <% authors.forEach(function(author) { %>
    <% if(typeof book !== 'undefined') { %>
      <option value="<%= author._id %>" selected=<%= (author._id.toString() == book.author._id.toString()) ? 'selected' : 'false' %>><%= author.name %></option>
    <% } else { %>
      <option value="<% author._id %>"><%= author.name %></option>
    <% } %>
  <% }) %>
</select>

转换是正确的。这里有点小错误,就是这样。谢谢我被抛出是因为错误消息出于某种原因指向第一个选项元素,而不是第二个我忘记了=符号的元素。
<option value="<%= author._id %>"><%= author.name %></option>
<select class="form-control" id="author" type="select" placeholder="Select author" name="author" required="true">
  <% authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;}); %>
  <% authors.forEach(function(author) { %>
    <% if(typeof book !== 'undefined' && 'author' in book) { %>
      <option value="<%= author._id %>" selected=<%= (author._id.toString() == book.author._id.toString()) ? 'selected' : 'false' %>><%= author.name %></option>
    <% } else { %>
      <option value="<%= author._id %>"><%= author.name %></option>
    <% } %>
  <% }) %>
</select>