简体   繁体   English

响应文件中的if语句

[英]if statements in a respond_to js file

I have a page that has ajax tabs that loads different actions in my controller to render a partial with different content. 我有一个页面,该页面具有ajax选项卡,这些页面可在控制器中加载不同的操作以呈现具有不同内容的部分。

So the index action of my controller has two remote: true links at the top. 因此,控制器的索引操作在顶部有两个远程链接:true链接。 Wich works fine, they render the corresponding partial appropriately using the respond_to js. Wich可以正常工作,它们使用react_to js适当地渲染了相应的部分。

#comments_stream.js.erb and likes_stream.js.erb
$("#masonry-container").html("<%= escape_javascript render('activities/activites') %>");

The problem is I am also paginating these partials kaminari and infinite scroll. 问题是我也在对这些部分kaminari和无限滚动进行分页。 so I dont want to run the code in the js.erb file above when my pagination fires because its just replacing (.html) my content instead of appending the new content the way infinite scroll script is trying to do (and does on my other pages). 所以我不想在我的分页触发时在上面的js.erb文件中运行代码,因为它只是替换(.html)我的内容,而不是以无限滚动脚本试图做的方式(以及对我的其他内容)附加新内容页)。

#pagination
<%= paginate @activities, remote: true %>

So, my real question is how can I make the .html("<%... only fire when the link in my tab is clicked and not when the pagination is fired. 所以,我真正的问题是如何使.html(“ <​​%...仅在单击选项卡中的链接时才触发,而在分页被触发时才触发。

I tried to target the remote action with a paramater, but couldn't get it to work. 我试图通过参数将远程操作作为目标,但无法使其正常工作。

 #original remote link
<%= link_to comments_stream_path, remote: true %>

#what I tried
<%= link_to comments_stream_path, remote: true, :item => 'comments_partial' %>

#comments.js.erb
<% if params[:item] == 'comments_partial' %>
  $("#masonry-container").html("<%= escape_javascript render('activities/activites') %>");
<% end %>

Any help would be greatly appreciated! 任何帮助将不胜感激! I've been messing with this for a while now... 我已经为此困扰了一段时间了...

我认为您传递的参数错误,请尝试:

<%= link_to comments_stream_path(:item => 'comments_partial'), remote: true %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM