【问题标题】:Rails, Bootstrap Modal, trigger code on modal openRails,Bootstrap Modal,模态打开时触发代码
【发布时间】:2018-03-14 23:13:44
【问题描述】:

我正在使用 Readable Gem,并在模态中使用 cmets。我想在用户打开 Bootstrap 模式时将评论标记为只读。有人可以指出我正确的方向以在用户打开模式时触发评论为只读吗?目前,它甚至在模式打开之前将评论标记为已读,因为我相信它正在运行代码而无需用户打开模式。

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

【问题讨论】:

    标签: javascript ruby-on-rails ruby twitter-bootstrap bootstrap-modal


    【解决方案1】:

    监听modal的on show事件,比如

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

    【讨论】:

      【解决方案2】:

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

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

      这个事件触发了显示的模式

      【讨论】:

      • 我已阅读文档...我只是不确定错误在哪里...在我的原始帖子中使用我的代码,“ ";即使模式没有打开也会触发......这就是我想要弄清楚的。
      • 我想这已经完成了整个页面的渲染。我建议为 ajax 更新创建一个端点,并通过 ajax 从事件块中进行。
      猜你喜欢
      • 2017-01-06
      • 2021-07-11
      • 2020-10-28
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 2017-07-24
      • 2013-10-31
      • 1970-01-01
      相关资源
      最近更新 更多