繁体   English   中英

Rails,Bootstrap Modal,模态打开时触发代码

[英]Rails, Bootstrap Modal, trigger code on modal open

我正在使用可读的宝石,并在模态中有注释。 我想在用户打开Bootstrap模式时将评论标记为只读。 当用户打开模态时,有人可以指出正确的方向来触发评论,即只读吗? 当前,它甚至在打开模式之前就将注释标记为已读,因为我认为它是在运行代码的情况下没有用户打开模式。

<script>
  $(('#picModal-<%= index %>').hasClass('show'), function(){
    "<% comment.mark_as_read! for: current_user %>";
  });
</script>

聆听模态的表演事件,例如

$('##picModal-<%= index %>').on('shown.bs.modal', function (e) { "<% comment.mark_as_read! for: current_user %>"; //do something else! })

假设您有一个CommentController。
在更新操作中设置comment.mark_as_read!

$('#picModal').on('shown.bs.modal', function(e){
      // Set ajax patch to the 'comments#update' with the comment id
    })

此事件触发了显示的模式

暂无
暂无

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

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