[英]x-editable how to get the id of clicked element
I am new to x-editable and jQuery so I am having an issue understanding how to get the "id" of a clicked element using x-editable, hopefully someone can help. 我是x-editable和jQuery的新手,所以我遇到了一个问题,了解如何使用x-editable获取被点击元素的“id”,希望有人可以提供帮助。
I have several links on my page within a div called #line_item_unit_cost. 我在一个名为#line_item_unit_cost的div中的页面上有几个链接。
<div id="line_item_unit_cost">
<a id="1">link</a>
<a id="2">link</a>
<a id="3">link</a>
<a id="4">link</a>
<a id="5">link</a>
</div>
When I click on one of the links I am firing an x-editable script that will allow me to do an inline edit. 当我点击其中一个链接时,我正在触发一个x-editable脚本,允许我进行内联编辑。 The issue I am having is that I need to pass in which line item I am working on so that I can update my db. 我遇到的问题是我需要传递我正在处理的项目,以便我可以更新我的数据库。 I dont know how (or I am doing it wrong) to access that "id" of the link I click. 我不知道如何(或我做错了)访问我点击链接的“id”。
Here is my script: 这是我的脚本:
$('#line_item_unit_cost a').editable({
validate: function(value) {
if($.trim(value) == '') return 'This value is required.';
},
type: 'text',
url: '/post',
pk: {{ purchaseOrder.id }},
title: 'Enter Value',
params: {
purchaseOrderId : {{ purchaseOrder.id }} ,
lineId : $(this).attr("id"),
text: 223
},
ajaxOptions: {
dataType: 'json'
},
success: function(response, newValue) {
}
});
This line: lineId : $(this).attr("id") gives me a null value. 这一行:lineId:$(this).attr(“id”)给我一个空值。
If I use lineId : $("#line_item_unit_cost a").attr("id") keeps pulling up the first instance on the page's "id", not the one that is being edited. 如果我使用lineId:$(“#line_item_unit_cost a”)。attr(“id”)不断提取页面上“id”的第一个实例,而不是正在编辑的实例。
Anyone know how to get the id of the link that I clicked using x-editable? 任何人都知道如何获取我使用x-editable单击的链接的ID?
Thanks so much!!! 非常感谢!!!
Decided I would offer the solution instead of deleting the post in case anyone else needed this... 决定我会提供解决方案而不是删除帖子以防其他人需要这个...
$('#line_item_unit_cost a').editable({
validate: function(value) {
if($.trim(value) == '') return 'This value is required.';
},
type: 'text',
url: '/poste',
pk: {{ purchaseOrder.id }},
title: 'Enter Freight Value',
params: function(params) {
var line = $(this).attr("id");
var data = {};
data['purchaseOrderId'] = params.pk;
data['field'] = params.name;
data['value'] = params.value;
data['lineId'] = line;
return data;
},
ajaxOptions: {
dataType: 'json'
},
success: function(response, newValue) {
}
});
$(custom_selector).each(function() {
var current_element = $(this);
$(this).editable({
//common code where you can use current_element
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.