晚上好,所有人都来这里!
此时我正在使用Oracle Apex中的一个页面(版本4.2.6.00.03)。它由两个经典报告组成 - 第一个是“主”报告,第二个包含前者的“细节”。还有几个按钮用于执行插入/更新/删除数据的动作。我的目的不仅是让行动起作用,而且“细节”报告在选择“主”行(我已完成这些任务)时刷新,而且还设法保存报告行的突出显示。执行操作(不仅仅是刷新页面)。
现在我将解释我已经做过的事情。可以通过我在每个Report的页脚中放入的脚本来选择行(并同时突出显示它),它看起来像这样:
<script>
$(".t20data","#master_report").live("click",function(){
chooseMST($(this).find("span.MASTER").attr("id"));
});
</script>
master_report 是“主”报告区域的ID, MASTER 代表span类,其中我将报告中的所有单元格包装起来以保留行的值ID。函数 chooseMST 是:
function chooseMST(docID){
$.post('wwv_flow.show',
{'p_request' : 'APPLICATION_PROCESS=SET_MASTER',
'p_flow_id' : $v('pFLowId'),
'p_flow_step_id' : $v('pFlowStepId'),
'p_instance' : $v('pInstance'),
'x01' : docID},
function(data){
//refreshes "details" report
$('#detail_report').trigger('apexrefresh');
//deletes color from all the rows of "master" report
$(".t20data","#master_report").parent("tr").children().css("background-color","#F2F2F5");
//highlights the chosen row in "master" report
$("#" + String(docID)).parent("td").parent("tr").children().css("background-color","#A3BED8");
}
);
}
动作(比方说,AJAX回调) SET_MASTER 是这样的:
begin
--clears the choice from "detail" report
APEX_UTIL.SET_SESSION_STATE(P_NAME => 'P400_DETAIL_RN'
,P_VALUE => NULL);
--makes the choice from "master" one
APEX_UTIL.SET_SESSION_STATE(P_NAME => 'P400_MASTER_RN'
,P_VALUE => APEX_APPLICATION.G_X01);
end;
要说清楚页面,我解决了清除隐藏项目 P400_DETAIL_RN 和 P400_MASTER_RN 的问题,方法是在此PL / SQL代码的标题之前进行处理:
begin
:P400_DETAIL_RN := APEX_UTIL.GET_NUMERIC_SESSION_STATE(P_ITEM => 'P400_DETAIL_RN');
:P400_MASTER_RN := APEX_UTIL.GET_NUMERIC_SESSION_STATE(P_ITEM => 'P400_MASTER_RN');
end;
以及每次加载页面时执行的Javascript函数 recolorRows :
function recolorRows(){
$(".t20data","#master_report").parent("tr").children().css("background-color","#F2F2F5");
if($("P400_MASTER_RN").val() != "") $("#" + String($("P400_MASTER_RN").val())).parent("td").parent("tr").children().css("background-color","#A3BED8");
$(".t20data","#detail_report").parent("tr").children().css("background-color","#F2F2F5");
if($("P400_DETAIL_RN").val() != "") $("#" + String($("P400_DETAIL_RN").val())).parent("td").parent("tr").children().css("background-color","#A3BED8");
}
“详细信息”报告中有关行的代码是相似的,所以我省略这一部分。从执行操作数据的操作开始出现问题。这是打开对话框窗口的功能,用于插入或更新在“主”报告中选择的行:
function MST_open(action){
//the part of code which finds out with what parameteres we should call the dialog window
$("#dialogFrame").attr("src",stringToCall);
$("#dialogWindow").dialog({
title:windowName,
modal:true,
width:500,
height:500,
resizable:true,
close:reloadMST //the action on closing the window
});
}
reloadMST 的代码如下所示:
function reloadMST(){
$("master_report").trigger('apexrefresh');
$("detail_report").trigger('apexrefresh');
}
在单击按钮(例如“更新”)的对话框窗口中执行的Javascript函数是:
function mstUpdate(){
$.post('wwv_flow.show',
{'p_request' : 'APPLICATION_PROCESS=MASTER_UPDATE',
'p_flow_id' : $v('pFLowId'),
'p_flow_step_id' : $v('pFlowStepId'),
'p_instance' : $v('pInstance'),
'x01' : apex.item("P402_SNAME").getValue()},
function(data){
//returns the ID of updated row in "msg" part of "res" variable
var res = eval("(" + data + ")");
if(res.status != "OK"){
//the code which catches the error, if it appears
} else {
parent.MST_close(res.msg);
}
}
);
}
其中 MST_close 是:
function MST_close(docID){
$("#dialogWindow").dialog("close");
//see this function above
chooseMST(docID);
}
因此,这是一系列Javascript和PL / SQL操作,涉及从“主”报告更新行。插入/更新/删除数据的操作很有用,但我不能说保存行的颜色是一样的。后者工作良好,而我只选择行或刷新页面,但在执行更新后,当前行失去突出显示。通过调试(例如,在Javascript代码中添加函数 console.log ),我发现必须导致保存突出显示的操作链在名义上执行,但它看起来像是刷新报告在着色后或仅阻止后者。
因此,我的问题是:即使打开和关闭子对话框窗口,有没有办法保存当前行的高亮显示?
答案 0 :(得分:1)
我认为问题在于,在更新模态窗口中的记录值后,您将刷新主页面中2个报告中的数据,从而丢失突出显示。
要解决此问题,请尝试在将执行javascript功能的区域:您的经典报告上的刷新后事件上创建动态操作 recolorRows()
。你也可以用javascript做到这一点。主要的想法是,在刷新2个报告(使用reloadMST()
或其他方法)后,您必须触发recolorRows()
。
答案 1 :(得分:1)
非常感谢Cristian_I。我最近解决了我的问题。我的错误是我没有在HTML代码中完成隐藏的项目绑定 - 换句话说,仅通过Javascript。看着隐藏项目的行为,我发现当我试图在jQuery函数$(“#hidden_item”)。val()的帮助下找到它们的值时,我得到了之前的值,但不是当前(即会话状态值)。所以这就是为什么我突出显示不稳定。
除了在刷新报告后立即触发动态操作之外,我应该在“着色”代码本身之前将这些字符串添加到我的函数 chooseMST 中:
$("#P400_MASTER_RN").val(docID); //binding to exact string
和
$("#P400_DETAIL_RN").val(""); //clearing the choice in the "details" report.
由于这个问题,重新定位行的问题刚刚消失!因此,现在我的页面非常出色:突出显示是稳定的,甚至插入后也会突出显示新行。