克隆行(复制记录)在Oracle Apex不工作

Clone Row (copy records) in Oracle Apex is not working

本文关键字:Oracle Apex 工作 记录 复制      更新时间:2023-09-26
<script type="text/javascript">
    function fn_CloneRow(pThis) {
        $(pThis).parent().parent().clone().appendTo($(pThis).parent().parent().parent());
    }

通过使用上面的代码,我能够将表格中单击的行克隆到表格的底部,但是我无法存储它们。当我更改克隆行的值时,在提交页面时将更新原始行,而不是添加新行。

这是因为在克隆行时也克隆了包含主键的元素。根据我的想法,可以使用以下元素:

  • 清空包含PK的输入元素(您需要找出这是否是数组f01或任何其他)。您的问题没有提供上下文),或者如果您使用rowid,则清除名称为"frowid"的输入元素
  • 清空包含行校验和的输入元素。这是一个名称为"fcs"的输入元素
  • 将包含记录状态(name = fcud)的输入元素设置为'C'。它用于确定对其执行什么操作。"D"是新的,"C"是改变的,"U"是更新的——我猜。这不是在任何文档中,但通过检查html和javascript你可以找到它。

如果不使用parent().parent()...,而是使用.closest(...)

查找最近的tr或表,可以进一步改进代码。
var newRow = $(pThis).closest('tr').clone();
$('input[name=f01]', newRow).val(""); //input with PK value -- make sure this matches your situation!!!
$('input[name=frowid]', newRow).val(""); //or if the form works with rowid, use this
$('input[name=fcs]', newRow).val(""); //clear the checksum
$('input[name=fcud]', newRow).val("C"); //set the record status
newRow.appendTo($(pThis).closest('table')); //finally, append the row to the table