2017-08-28 66 views
2

我需要在HTML页面中列出很多项目。在合理范围内一次显示的项目太多。我曾见过与Ecto一起使用的工具来处理EEX模板中的寻呼机。但是,在我的控制器中,我从外部数据源提取这些数据,并且无法用Ecto查询它。下面的模板文件inventory.html.eex。无Ecto的EEX模板中的寻呼机 - Elixir和Phoenix

<div class="section-content"> 
 
    <div class="section-row"> 
 
    <div class="section-cell"> 
 
     <h3> Current Inventory: </h3> 
 
     <table class="table"> 
 
     <thead> 
 
      <tr> 
 
      <th>Product Title</th> 
 
      <th>Product ID</th> 
 
      </tr> 
 
     </thead> 
 
     <tbody> 
 
     <%= for product <- @products do %> 
 
      <tr> 
 
      <td><%= product["title"] %></td> 
 
      <td><%= product["id"]%></td> 
 
     </tr> 
 
     <% end %> 
 
     </tbody> 
 
     </table> 
 
    </div> 
 
    </div> 
 
</div>

什么是处理这个数据的分页好的解决办法?

回答

4

您可以在模板中使用scriviner_html库作为分页助手。 这只需要从控制器填充一个%Scriviner.Page{}结构体并将其传递给render

Page结构相当简单,所以你可以从外部源列表或者一个API来填充它:

defstruct [:entries, :page_number, :page_size, :total_entries, :total_pages]