[英]How to display music in a category when a category is clicked (without a page refresh) in Ruby on Rails?
I am building a website for a music database.我正在为音乐数据库建立一个网站。
I would like to display categories like classical and hip hop first;我想先显示古典和嘻哈等类别; when the user clicks on a category, I would like to display all the tracks names in that category (I would like to do this without a page refresh).
当用户单击某个类别时,我想显示该类别中的所有曲目名称(我想在不刷新页面的情况下执行此操作)。 I would also need to support pagination of this list displaying 10 items in one page (and I need to display buttons for display, edit, delete alongside each track in this list)
我还需要支持此列表的分页,在一页中显示 10 个项目(并且我需要在此列表中的每个曲目旁边显示用于显示、编辑、删除的按钮)
How can I accomplish this?我怎样才能做到这一点? Does bootstrap provide components that support this kind of implementation?
bootstrap 是否提供支持这种实现的组件?
(If I could do this with a page refresh, I have done this before and I would know how to do it. But I am not sure how to do this without a page refresh) (如果我可以通过页面刷新来做到这一点,我以前已经这样做了,我会知道如何做到这一点。但我不知道如何在没有页面刷新的情况下做到这一点)
On views/categories/index.html.erb:在视图/类别/index.html.erb 上:
<% @categories.each do |category| %>
<%= link_to category_path(category), :remote => true do %>
<%= category.name %>
<% end %>
<div class="category_<%= category.id %>">
</div>
<% end %>
Then create a partial views/categories/_show.html.erb (here you can insert a table or a structure with bootstrap row and columns):然后创建一个部分 views/categories/_show.html.erb(在这里你可以插入一个表格或一个带有引导行和列的结构):
<% @category.tracks.each do |track| %>
<%= track.name %>
... and you can add here delete and edit actions
<% end %>
Then create views/categories/show.js.erb:然后创建views/categories/show.js.erb:
$(".category_<%= @category.id %>").html("<%= escape_javascript(render("show")) %>");
Fyi what you are trying to do has nothing to do with bootstrap, unless you wanted for instance display tracks on a bootstrap modal.仅供参考,您尝试执行的操作与引导程序无关,除非您希望例如在引导程序模态上显示轨道。
Here is a poor man's bootstrap example I whipped up: when you click on the Track Category
example, the table should expand.这是我创建的一个穷人的引导程序示例:当您单击
Track Category
示例时,表格应该展开。 (You must have bootstrap v4 set up for this to work) and you must have a track_table
partial as well - you can use the same partial for the two different tables that you want: (您必须为此设置 bootstrap v4)并且您还必须有一个
track_table
部分 - 您可以为您想要的两个不同表使用相同的部分:
<div class="track-group">
<div class="track track-default">
<div class="track-heading">
<h4 class="track-title">
<p data-toggle="collapse" href="#collapse1"> Track Category (Click to Expand)</p>
</h4>
</div>
<div id="collapse1" class="track-collapse collapse">
<div class="track-body">
<%= render 'track-table' %>
</div>
<div class="track-footer">
</div>
</div>
</div>
</div>
Here's how it looks with an existing app on my computer:这是我计算机上现有应用程序的外观:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.