【问题标题】:How to sent an id outside the loop of handlebars to the form inside the handlebars?如何将车把循环外的 id 发送到车把内的表单?
【发布时间】:2021-11-15 13:46:28
【问题描述】:
   <form method="POST"  action="/admin/update-blog/{{blogs._id}}"> 
  <div class="form-group">
  
    <label for="exampleInputPassword1">HEADING</label>
    <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{blogs.heading}}" name="heading">
  </div>
  <br><br>
  <div class="form-group">
    <label for="exampleInputPassword1">BLOG</label>
    <input type="text" class="form-control" id="exampleInputPassword1" value="{{blogs.blog}}" name="blog">
  </div>

  <button type="submit" class="btn btn-primary">Submit</button>
</form>
<br><br>
<h2><i><b>Comments</b></i></h2>
<table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Email</th>
      <th scope="col">Message</th>

    </tr>
  </thead>
  <tbody>
    {{#each blogs.comments}}
    <tr>
      <th scope="row"></th>
 
            <td>
       <form method="POST" action="/admin/delete-comment">
  <div class="form-group">
    <label for="exampleInputEmail1"></label>
    <input type="email" class="form-control" id="myInput"readonly aria-describedby="emailHelp" placeholder="Enter email" value="{{this.email}}" name="email">
  </div>
  <button type="submit" class="btn btn-danger">delete</button>
</form>

      </td>
      <td>{{this.message}}</td>
 
    </tr>
    {{/each}}
  </tbody>
</table>

我怎样才能将 {{blogs._id}} 传递给一个名为 {{#each blogs.cmets}} 的循环内的表单。这可能吗。我正在尝试根据电子邮件删除评论和博客的 id。这里的博客 id 位于代码顶部,这是它显示博客的第一种形式。在第二种形式中,它显示博客的 cmets。 对我来说,不可能将 id 从博客传递到第二个循环(显示评论)。 我想在第二个循环中将博客的 id 传递给表单的操作(显示评论)

提前感谢????

【问题讨论】:

标签: node.js loops handlebars.js


【解决方案1】:
<option value="{{id}}">{{title}} {{../externalValue}}</option>

//The ../ path segment references the parent template scope that should be what you want.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2012-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多