因此,我试图在视图中呈现两个表单信息,但我可以获取一个表单信息进行渲染,但是无法获取第二个表单来呈现必要的信息。

这是我到目前为止所拥有的。

<tbody>
                {{#each poemRegistrations}}
                <tr>
                    <td><a href="/dashboard/users/{{_id}}/progress">{{schoolName}}</a></td>
                    <td>{{competitionResults.winnersName}}</td>
                    <td>{{poem1AuthorName}}</td>
                    <td>{{poem1Title}}</td>
                    <td>{{poem1Url}}</td>
          <td>{{poem2AuthorName}}</td>
                    <td>{{poem2Title}}</td>
                    <td>{{poem2Url}}</td>
          <td>{{poem3AuthorName}}</td>
                    <td>{{poem3Title}}</td>
                    <td>{{poem3Url}}</td>
                    <td>
                        <div class="btn-group">
              <a href="/dashboard/users/forms/poem-registrations/{{_id}}">
                                <button class="btn">Show</button>
                            </a>
              <a href="/dashboard/users/forms/poem-registrations/edit/{{_id}}">
                                <button class="btn">Edit</button>
                            </a>
              <a href="/dashboard/users/forms/poem-registrations/delete/{{_id}}">
                                <button class="btn user-btn-danger">Delete</button>
                            </a>
                        </div>
                    </td>
                </tr>
                {{/each}}

router.get('/dashboard/all-poems', ensureAuthenticated, (req, res) => {
  PoemRegistrations.find({}, function(err, poemRegistrations, competitionResults) {
    res.render('dashboard/all-poems.hbs', {
      pageTitle: 'All Poems',
      poemRegistrations: poemRegistrations,
      competitionResults: competitionResults
    });
  });
});


PoemRegistration表单信息正在呈现,但是我只想从另一种表单中获得获奖者的名字。

我将如何去做呢?

最佳答案

您可以在Handlebars V2.0.0中使用{{@root}}帮助器:{{@root.competitionResults.winnersName}}

或者,您也可以包括../个段以将上下文更改为根:{{../competitionResults.winnersName}}

希望这可以帮助。

09-25 17:31