每个街区通过多个参数车把

时间:2018-02-12 12:16:40

标签: javascript node.js handlebars.js express-handlebars

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

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

<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表单信息正在呈现,但我只想从其他表单中获取获奖者名称。

我将如何做到这一点?

1 个答案:

答案 0 :(得分:0)

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

或者您还可以添加../段来更改根目录的上下文:{{../competitionResults.winnersName}}

希望这有帮助。