简体   繁体   English

jQuery Jeditable Codeigniter发送多个值

[英]Jquery Jeditable Codeigniter sends multiple values

I have an ID that is Databases ID of the row I want to update, then is the new value that is submited, when pressing enter. 我有一个ID,它是我要更新的行的数据库ID,然后是在按Enter键时提交的新值。 What I want to do is assign the database cell which needs to be updated as a rel value. 我要做的是分配需要更新为相关值的数据库单元。 At the moment it only submits db_cell_1 no matter which cell I press to edit. 目前,无论我按哪个单元格进行编辑,它都仅提交db_cell_1。 If I press the second cell in my html page, I want it to submit db_cell_2 I hope that I made myself clear about the problem I'm facing. 如果我在html页面中按下第二个单元格,则希望它提交db_cell_2,希望我能清楚自己所面临的问题。 Any pointers in the right direction will be appreciated. 在正确方向上的任何指针将不胜感激。

HTML: HTML:

<td  id="<?echo $value['ID'];?>" class="merv_editable" rel="db_cell_1" style="text-align: left;" > <?echo $value['nom_nosauk'];?></td>
<td id="<?echo $value['ID'];?>" class="merv_editable" rel="db_cell_2"><?echo $value['merv'];?></td>

JQuery: JQuery的:

$('.merv_editable').click(function(){

  var attrval = $(this).attr('rel');

    $('.merv_editable').editable('http://www.draugiem.lv',{
        id   : 'elementid',
        name : 'newvalue',
        submitdata : {pzid : attrval}
    });
});

The issue is related to using the class as the invoker of the editable call. 问题与使用类作为editable调用的调用者有关。 Since you are already inside one instance of potentially many from a class (from the click event is of a single element) you have scope of $(this) which references just the singular element that was clicked. 因为您已经在一个类中可能存在许多实例(单击事件是单个元素)中,所以您具有$(this)范围,它仅引用被单击的单个元素。 You can then pass this element to the editable call to invoke the correct element, not just the first one in source code. 然后,您可以将此元素传递给可编辑的调用,以调用正确的元素,而不仅仅是源代码中的第一个元素。

To rectify, the code simply needs to reference the currently invoked element, which is shortcut with the $(this) directive. 要进行纠正,代码只需引用当前调用的元素,这是$(this)指令的快捷方式。

$('.merv_editable').click(function(){
      var attrval = $(this).attr('rel');

    $(this).editable('http://www.draugiem.lv',{
        id   : 'elementid',
        name : 'newvalue',
        submitdata : {pzid : attrval}
    });
});

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

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