首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >x-editable on按钮,如何编辑具体的评论?

x-editable on按钮,如何编辑具体的评论?
EN

Stack Overflow用户
提问于 2016-05-04 22:21:07
回答 1查看 852关注 0票数 1

我已经添加了x-editable注释来编辑按钮,但是我不知道编辑按钮如何发现哪个对象在编辑?

代码语言:javascript
复制
<% commentable.comments.each do |comment| %>
    <div class="well">
      <a  href="#" data-xeditable="true" data-pk="<%= comment.id %>"
          style="border:none; color:black; text-decoration: none !important;cursor: default;"
          id="edit-comment"
          data-model="comment"
          data-name="content"
          data-type="text"
          method="put"
          data-toggle="manual"
          data-url="<%= comment_path(comment) %>">
          <%= comment.content %>
      </a>
      <div class="btn btn-default" id="edit-button" style="float:right;"> 
        <span class="glyphicon glyphicon-edit" aria-hidden="true"> Edit </span> 
      </div>
    </div>

我的Js:

代码语言:javascript
复制
/* X-Editable*/
$(function() {
  $.fn.editable.defaults.mode = 'inline';
  return $("[data-xeditable=true]").each(function() {
    return $(this).editable({
      ajaxOptions: {
        type: "PUT",
        dataType: "json"
      },
      params: function(params) {
        var railsParams;
        railsParams = {};
        railsParams[$(this).data("model")] = {};
        railsParams[$(this).data("model")][params.name] = params.value;
        return railsParams;
      }
    });
  });
});
$(function() {
$('#edit-button').click(function(e) {
    e.stopPropagation();
    $('#edit-comment').editable('toggle');
});
});

结果是:当我点击编辑按钮时,我可以编辑第一条评论,它的id是:" edit - comment“。问题:当我在循环中创建下一个注释,并且这个注释具有相同的id :)时开始,触发器上的第二个编辑按钮如何知道哪个注释(对象)编辑?

EN

回答 1

Stack Overflow用户

发布于 2016-05-05 18:56:28

好了,我得到了解决方案。“查找父对象按钮,然后使用类edit-comment查找迭代对象,并在该元素上使用切换”

当我理解这个逻辑时,我只需要使用正确的语法:

代码语言:javascript
复制
$(function() {  
    $('.edit-button').click(function(e) {
      e.stopPropagation();
      $(this).parent().find(".edit-comment").editable('toggle');
    });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37030537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档