我已经添加了x-editable注释来编辑按钮,但是我不知道编辑按钮如何发现哪个对象在编辑?
<% 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:
/* 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 :)时开始,触发器上的第二个编辑按钮如何知道哪个注释(对象)编辑?
发布于 2016-05-05 18:56:28
好了,我得到了解决方案。“查找父对象按钮,然后使用类edit-comment查找迭代对象,并在该元素上使用切换”
当我理解这个逻辑时,我只需要使用正确的语法:
$(function() {
$('.edit-button').click(function(e) {
e.stopPropagation();
$(this).parent().find(".edit-comment").editable('toggle');
});
});https://stackoverflow.com/questions/37030537
复制相似问题