使用 JavaScript 循环遍历 APEX 应用程序项
Using JavaScript to Loop through APEX Application Items
我在 Oracle APEX 上工作,我有一个交互式报告以表格形式显示列和行。在报告中,我对大多数可编辑的列使用了 "apex_item" { each having it's item_id } 。
现在,有三列,一列具有预定义的只读值,一列用于输入新值,另一列用于显示两者之间的差异。
我无法编写 javascript 代码来对报告中对应于这 3 列的所有行执行上述操作。它只对我的第一行有效。
示例如下:
1. APEX_ITEM.TEXT(9,abc, p_item_id=>'p09')
2. APEX_ITEM.TEXT(9,xyz, p_item_id=>'p10')
3. APEX_ITEM.TEXT(9,def,p_attributes =>'readonly', p_item_id=>'p11')
-- document.getElementById("p10").value --> This is only referring to the
value for the first row for that column (p10).
我需要item_id 'p11'来反映当我在p10中输入值时p10和p09的值的差异。需要它在该列的所有行中工作。
我这里用的是jQuery。首先为每列的行添加一个公共类名。我在这里提供与 id 相同的类名。
$('[id]').each(function() {
var ids = $('[id="p09"]');
if (ids.length > 1 && ids[0] == this) {
$('#' + this.id).addClass('p09');
}
var ids = $('[id="p10"]');
if (ids.length > 1 && ids[0] == this) {
$('#' + this.id).addClass('p10');
}
var ids = $('[id="p11"]');
if (ids.length > 1 && ids[0] == this) {
$('#' + this.id).addClass('p11');
}
});
现在您可以开始对以下元素进行循环:-
$(".p9").each(function(){
$(this).val() = $(this).siblings(".p11").val() - $(this).siblings(".p10").val();
});
嗯,这就是我解决问题的方法。我正在使用 'PThis',它基本上是一个 this 指针,它指向我报告中的每个单元格。我正在使用它来找出该特定单元格属于哪一行,并使用该行号访问我的计算将生效的其他单元格。
看这个函数,代码应该是self-explanatory。
function change(pThis)
{
var row = pThis.id.split('_')[1];
var xyz= parseFloat(document.getElementById("xyz"+row).value) ;
var abc= parseFloat(document.getElementById("abc"+row).value) ;
var def= parseFloat(xyz)-parseFloat(abc);
def= Math.round(def*100)/100;
document.getElementById("def"+row).value = def;
}
我在 Oracle APEX 上工作,我有一个交互式报告以表格形式显示列和行。在报告中,我对大多数可编辑的列使用了 "apex_item" { each having it's item_id } 。
现在,有三列,一列具有预定义的只读值,一列用于输入新值,另一列用于显示两者之间的差异。
我无法编写 javascript 代码来对报告中对应于这 3 列的所有行执行上述操作。它只对我的第一行有效。
示例如下:
1. APEX_ITEM.TEXT(9,abc, p_item_id=>'p09')
2. APEX_ITEM.TEXT(9,xyz, p_item_id=>'p10')
3. APEX_ITEM.TEXT(9,def,p_attributes =>'readonly', p_item_id=>'p11')
-- document.getElementById("p10").value --> This is only referring to the
value for the first row for that column (p10).
我需要item_id 'p11'来反映当我在p10中输入值时p10和p09的值的差异。需要它在该列的所有行中工作。
我这里用的是jQuery。首先为每列的行添加一个公共类名。我在这里提供与 id 相同的类名。
$('[id]').each(function() {
var ids = $('[id="p09"]');
if (ids.length > 1 && ids[0] == this) {
$('#' + this.id).addClass('p09');
}
var ids = $('[id="p10"]');
if (ids.length > 1 && ids[0] == this) {
$('#' + this.id).addClass('p10');
}
var ids = $('[id="p11"]');
if (ids.length > 1 && ids[0] == this) {
$('#' + this.id).addClass('p11');
}
});
现在您可以开始对以下元素进行循环:-
$(".p9").each(function(){
$(this).val() = $(this).siblings(".p11").val() - $(this).siblings(".p10").val();
});
嗯,这就是我解决问题的方法。我正在使用 'PThis',它基本上是一个 this 指针,它指向我报告中的每个单元格。我正在使用它来找出该特定单元格属于哪一行,并使用该行号访问我的计算将生效的其他单元格。
看这个函数,代码应该是self-explanatory。
function change(pThis)
{
var row = pThis.id.split('_')[1];
var xyz= parseFloat(document.getElementById("xyz"+row).value) ;
var abc= parseFloat(document.getElementById("abc"+row).value) ;
var def= parseFloat(xyz)-parseFloat(abc);
def= Math.round(def*100)/100;
document.getElementById("def"+row).value = def;
}