2017-08-06 80 views
1

我有一个模态窗口,可以动态填充。点击按钮后,它将在表中的每一行打开。这里有一个例子:Javascript,X-Editable只更新第一个提交的数据,但不是第二个

<!-- 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> 

这是我如何填写表格:

// 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' 
    }); 
} 

但问题是,每个模态打开时,它的工作好。所有的数据填写没有任何错误。所有的文本都像在表格中一样。模式中的所有PK变化,当我编辑/保存文本时,它的效果很好。但是在我第二次提交表格后,它只会改变我第一次提交的第一个“PK”。但不是新的,每次打开模式都会更新。

回答

0

更新:现在的作品,因为它suposed的工作,但是,只有当我把:

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

权利之前:

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