【发布时间】:2018-02-09 14:23:03
【问题描述】:
我对产品进行了描述,其中一半的文本会在单击阅读更多链接时显示。一行中有许多带有描述的产品。这些产品来自轨道上的红宝石循环。所以我为每个产品描述提供剩余的文本类,如 class1、class2、class3 等。
然后对于一个产品描述,我将 javascript 编写为:
$(function(){
$('.read_more1').click(function(event){
event.preventDefault();
$('.more_text1').show();
$('.read_more1').hide();
});
});
但是由于产品的数量是随机的。那么,我如何迭代该类以使所有产品数量的阅读更多链接的工作都存在。
Ruby .html.erb 代码
<% if @example[:products] %>
<% @example.company.each do |company| %>
<% if !company[:display_company] %>
<div class="field no_margin">
<b class="space-bold"><%= company[:category_name].titleize %>
</b>
<% file_name =
get_file_name_from_url(company.public.first.photo_url) %>
<%= link_to image_tag(file_public_path(url: @example[:url], \
id: company._id.to_s, mod_id: company.public.first._id.to_s, \ ), \
company_public_path(url: @example[:url], id: company._id.to_s) %>
<div class="linespace">
<%= ("company[:category])[0..30]} #{ link_to t('more'), \
{ :pics=> true}, { :class => "read_more#{count}"}} <text class=more_text#{count}>#{t(company[:category])[31..-1]}
</text>").html_safe %><br />
<% count += 1 %>
</div>
</div>
<% end %>
理解起来很复杂。
【问题讨论】:
-
如果有人想了解更多信息,可以询问
-
您能否提供 2 或 3 个产品的示例 html
-
尝试提供一个 sn-p (jsfiddle) 也许?并模拟产品的描述,对理解你想要达到的目标很有帮助。
标签: javascript css ruby-on-rails