【问题标题】:Horizontally order the <th> tag of a table with NodeJs and Handlebars使用 NodeJs 和 Handlebars 水平排列表格的 <th> 标签
【发布时间】:2019-08-02 21:11:13
【问题描述】:

怎么样,我试着咨询一下 NodeJs、Mysql 和 Handlebars。 查询的结果我没有问题。 BD中的表格如下。

水果桌

Id    fruit
1     Apple
2     Mango
3     Strawberry

您进行查询的文件

Fruit.js

router.get('/', isLoggedIn, async (req, res) => {

  const fruitAll = await db.query('SELECT  * FROM fruit ’);

res.render(‘fruit’, {fruitAll});
});

我执行视图的文件如下。

List.hbs

{{#each fruitAll}}
<div class="container p-4">
  <table border="1">
    <tr>
      <th>{{fruit}}</th>
    </tr>
    <tr>
      <th>Example 1</th>
      <th>Example 2</th>
      <th>Example 3</th>
    </tr>
  </table>
</div>
{{/each}}

结果如下:

--------------
Apple
--------------
Example 1
--------------
Mango
--------------
Example 2
--------------
Strawberry
--------------
Example 3
--------------

我想要的是如何水平放置水果。我的意思是这样。

______________________________
|Apple   |Mango   | Strawberry|
_______________________________
|Example1|Example2| Example3  |
–––––––––––––––––––––––––––––––

【问题讨论】:

    标签: mysql node.js handlebars.js


    【解决方案1】:

    会是:

    <div class="container p-4">
      <table border="1">
        <tr>
         {{#each fruitAll}}
          <th>{{fruit}}</th>
          {{/each}}
        </tr>
        <tr>
          <th>Example 1</th>
          <th>Example 2</th>
          <th>Example 3</th>
        </tr>
      </table>
    </div>
    

    因为您需要更多th 标签。在您的情况下,&lt;div&gt;..&lt;/div&gt; 被复制fruitAll.length(在这种情况下为 3)时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      • 1970-01-01
      • 2013-12-14
      • 2011-04-27
      • 2015-04-07
      相关资源
      最近更新 更多