简体   繁体   English

Javascript,X-Editable仅更新第一个提交的数据,而不更新第二个提交的数据

[英]Javascript, X-Editable is updating only the first submitted data, but not the second

I have a modal window, that I fill dynamically. 我有一个模式窗口,可以动态填充。 It opens for every row in a table after clicking a button. 单击按钮后,它将为表中的每一行打开。 Here is an example: 这是一个例子:

<!-- The Modal -->
<div id="callModal" class="callModal">
     <!-- Modal content -->
    <div class="modalCall-content">
      <div class="modalCall-header">
        <span class="closeModal">&times;</span>
        <h2 id="nameOfCalled">Modal Header</h2>
      </div>
      <div class="modalCall-body">
        <p class="shortNoteOfLeadClass" id="shortNoteOfLead" style="font-size:25px;"></p>
        <p>There will be statuses, notes and last call info...</p>
      </div>
      <div class="modalCall-footer">
        <h3><button type="button" class="btn btn-danger">End Call</button></h3>
      </div>
    </div> 
</div>

This is how I fill the form: 这是我填写表格的方式:

// Get the modal
var modal = document.getElementsByClassName('callModal')[0];
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("closeModal")[0];

// When the user clicks on the button, open the modal
function callThisTel(telID) {
    var leadName = document.getElementById("leadName_"+telID).textContent;
    var leadDescript = document.getElementById("leadDescript_"+telID).textContent;
    var assignedTo = document.getElementById("leadAssignedTo_"+telID).getAttribute("data-title");
    var currentProfile = document.getElementsByClassName("staff-profile")[0].getAttribute("alt");
    document.getElementsByClassName("shortNoteOfLeadClass")[0].setAttribute("data-pk", telID);

    document.getElementById("nameOfCalled").textContent = leadName;
    document.getElementsByClassName("shortNoteOfLeadClass")[0].textContent = leadDescript;
    modal.style.display = "block";
    $.fn.editable.defaults.mode = 'inline';
    $('.shortNoteOfLeadClass').editable({
        url: '<?php echo base_url('changeData.php'); ?>',
        pk: telID,
        type: 'text',
        title: 'Change description'
    });
}

But the problem is, that every time the modal opens, it works good. 但是问题在于,每次打开模式时,它都运行良好。 All the data fills in without any error. 所有数据填写正确无误。 All texts are as they are in the table. 所有文本均与表格中的内容相同。 All the PK change in the modal and when I edit/save text it works good. 模式中所有的PK更改,当我编辑/保存文本时,效果很好。 But after I submit the form second time, it changes only the first "pk" I was submitting at the first place. 但是,当我第二次提交表单后,它仅更改了我最初提交的第一个“ pk”。 But not the new ones, that are updated every time I open the modal. 但不是新的,每次我打开模态时都会更新。

Update: now it works as it suposed to work, but, only if I put: 更新:现在它可以正常工作了,但是,只有在我提出以下条件时:

$('.shortNoteOfLeadClass').editable("destroy");

Right before: 就在之前:

document.getElementsByClassName("shortNoteOfLeadClass")[0].setAttribute("data-pk", telID);

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

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