【问题标题】:How can I make a "FOR"(loop) in html, using chameleon and pyramid in python 3.4?如何在 python 3.4 中使用变色龙和金字塔在 html 中创建“FOR”(循环)?
【发布时间】:2014-10-25 18:38:51
【问题描述】:

如何在我的 html 中使用变色龙和金字塔进行循环? 我搜索但我没有找到类似的东西=/ 在这种情况下更容易使用javascript吗? 我在 MACADMIN(引导主题)中使用数据表。

<div class="table-responsive">
  <table cellpadding="0" cellspacing="0" border="0" id="data-table" width="100%">
    <thead>
      <tr>
        <th>
          Rendering engine
        </th>
        <th>
          Browser
        </th>
        <th>
          Platform(s)
        </th>
        <th>
          Engine version
        </th>
        <th>
          CSS grade
        </th>
      </tr>
    </thead>
    <tbody>
         Maybe put FOR here? like {for x items in "TABLE"}
      <tr>
        <td>
          {orgao_doc[x].nome}
        </td>
        <td>
          {orgao_doc[x].cargo}
        </td>
        <td>
          {orgao_doc[x].coleta}
        </td>
        <td>
          {orgao_doc[x].email}
        </td>
        <td>
          {orgao_doc[x].endereco}
        </td>
      </tr>
    </tbody>
  </table>
  <div class="clearfix">
  </div>
</div>

【问题讨论】:

    标签: python python-3.x pyramid chameleon template-tal


    【解决方案1】:

    使用tal:repeat attribute 重复模板的某些部分,给定一个序列:

    <tbody>
      <tr tal:repeat="item orgao_doc">
        <td>${item.nome}</td>
        <td>${item.cargo}</td>
        <td>${item.coleta}</td>
        <td>${item.email}</td>
        <td>${item.endereco}</td>
      </tr>
    </tbody>
    

    &lt;tr&gt; 标签被重复插入到输出中,orgao_doc 中的每个元素一次。在渲染这部分模板时,名称item 绑定到每个元素。

    【讨论】:

    • 我在 chameleon 的文档中看到了“tal”,我不明白。谢谢,它工作正常,但我需要把 $ {item.nome} 之前像 ${item.nome}
    猜你喜欢
    • 2013-04-02
    • 2011-08-27
    • 2023-03-03
    • 2016-11-21
    • 1970-01-01
    • 2011-12-07
    • 2011-12-25
    • 2015-04-07
    • 1970-01-01
    相关资源
    最近更新 更多