gpt4 book ai didi

javascript - Cognos 将值传递给所有提示

转载 作者:行者123 更新时间:2023-11-28 08:02:54 25 4
gpt4 key购买 nike

因此,我在报告中使用了 jQuery,并且我有一套报告,由于 jQuery 的帮助,所有报告一次全部加载,因此客户感觉转换速度更快,因为他们不必在每次单击之间等待。我希望能够根据客户使用的提示更改所有报告。因此,如果他们选择特定的一天,套件中的所有报告都将更改为该天。或者,如果他们选择了特定区域,则所有报告都会发送到该区域。这样客户就不必在每个报告的提示中加载参数。我想知道是否有办法做到这一点。我已经看过了,但没有发现任何东西。

编辑..因此,在我的报告中,包含所有 iframe 和我命名为changeMonth 的值提示,我有这个 JS

<script>
var report = cognos.Report.getReport("_THIS_");
var radio = report.prompt.getControlByName('monthChange');

var currentRadioValue = radio.getValues()[0]; //Get initial value object

radio.setValidator(validateRadio); //Define function to validate prompt

function validateRadio(values) {
if (values && values.length > 0 && values[0].use != currentRadioValue.use) { //Only do anything if control has value and has changed
currentRadioValue = values[0]; //Assign new value for later comparison
for (var i=0; i<window.frames.length; i++) { //Loop through all iFrames
window.frames[i].changeValue(values[0].use); //Call the changeValue function passing in the radio button value
}
}
return true; //Indicates the prompt is valid
}
</script>

在我想要 iframe 的报告中,我有一个值提示,它是一个下拉列表,其中 HTML 标记中包含此代码。

<script>
function changeValue(str){
var report = cognos.Report.getReport("_THIS_"); //Grab a handle for the report
var control = report.prompt.getControlByName('monthChange'); //Grab a handle for the prompt control
control.addValues([{"use":str,"display":str}]); //Change the prompt to the passed in value
report.sendRequest(cognos.Report.Action.REPROMPT); //Reprompt the page
}
</script>

如果重要的话,它们都是下拉列表。我看到您将它们列为单选按钮,所以我稍后会在这里尝试一下,并让您知道这是否改变了任何内容。但是我如何设置它,我还应该做其他事情吗?

最佳答案

我可以通过在每个子报告中创建一个 JavaScript 函数来实现此功能,该函数更改查询所依赖的隐藏提示值,然后重新提示页面。以下是每个子对象中需要的代码部分:

child 报告代码

<script>
function changeValue(str){
var report = cognos.Report.getReport("_THIS_"); //Grab a handle for the report
var control = report.prompt.getControlByName('controlname'); //Grab a handle for the prompt control
control.addValues([{"use":str,"display":str}]); //Change the prompt to the passed in value
report.sendRequest(cognos.Report.Action.REPROMPT); //Reprompt the page
}
</script>

这利用了 Cognos 版本 10.2 中添加的 Cognos JavaScript Prompt API。 getReport、getControlByName、addValues 和 sendRequest 函数都是 Cognos 提供的函数,目的是让 JavaScript 中的提示处理变得更容易。这里有更多信息:

Cognos JavaScript Prompt API documentation

在容器报告中,我创建了一个 Cognos 单选按钮值提示。我对 JavaScript 进行了编码,以利用 API 中 Cognos 提供的内置 onchange 验证 Hook 在单选按钮发生更改时运行代码。该代码循环遍历所有 iFrame,并调用上面在每个子报表中定义的函数,传入所选单选按钮的值。

容器报告代码

<script>
var report = cognos.Report.getReport("_THIS_");
var radio = report.prompt.getControlByName('radio');

var currentRadioValue = radio.getValues()[0]; //Get initial value object

radio.setValidator(validateRadio); //Define function to validate prompt

function validateRadio(values) {
if (values && values.length > 0 && values[0].use != currentRadioValue.use) { //Only do anything if control has value and has changed
currentRadioValue = values[0]; //Assign new value for later comparison
for (var i=0; i<window.frames.length; i++) { //Loop through all iFrames
window.frames[i].changeValue(values[0].use); //Call the changeValue function passing in the radio button value
}
}
return true; //Indicates the prompt is valid
}
</script>

请注意,在上面的代码中,字符串“controlname”和“radio”对应于相关提示控件的 Name 属性。默认情况下,Cognos 不会为提示控件指定名称。因此,您必须在创建后提供名称。无论您给它们起什么名称,脚本都必须进行相应的调整,以允许 JavaScript 访问它们的 Cognos Prompt API 对象。

可以修改此技术,以从 Cognos 中可用的各种提示控件中获取输入。此外,理论上,容器甚至根本不必是 Cognos。它可以是一个独立的网页,其中包含当标准 HTML onchange 事件触发时调用 iFrame 中的 JavaScript 函数的控件。唯一需要注意的是,由于安全限制,浏览器不允许从具有与 iFrame 不同域的容器调用 iFrame 内的函数。这是设计解决方案时需要考虑的事情。

关于javascript - Cognos 将值传递给所有提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25168822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com