简体   繁体   English

Spotfire-用于触发IronPython脚本以在报表加载时执行的JavaScript

[英]Spotfire - javascript to trigger IronPython script to be executed on report load

I have the follwing javascript code that it triggers an IronPython script when I load the report. 我有下面的javascript代码,当我加载报告时,该代码会触发IronPython脚本。

The only issue I have is that for a reason I don't know it does it (it triggers the script) a couple of times. 我唯一的问题是由于某种原因我不知道它会执行几次(它会触发脚本)。

Can some one help me? 有人能帮我吗? below is the script: 下面是脚本:

var n=0;

$(function () {
 function executeScript() {
     if (n==0){
        n=n+1;
        now = new Date();
        if (now.getTime()-$('#hiddenBtn input').val()>10000){
            $('#hiddenBtn input').val(now.getTime());
            $('#hiddenBtn input').focus();
            $('#hiddenBtn input').blur();
        }
     }
 }
$(document).ready(function(){executeScript()}); 
strong text});

Please, let me know if you need more information. 请让我知道是否需要更多信息。 Thanks in advance!!! 提前致谢!!!

I have had similar issues with Javascript executing multiple times. 我有多次执行Javascript的类似问题。 Spotfire seems to instance the JS more than once, and it can cause some interesting behavior... Spotfire似乎多次实例化JS,并且可能导致一些有趣的行为...

the best solution, in my opinion, only works if users are accessing the document via a link (as opposed to browsing the library). 我认为,最好的解决方案仅在用户通过链接访问文档(而不是浏览库)时才有效。 pass a configuration block to set a document property with a current timestamp, which would execute your IP script. 传递一个配置块以使用当前时间戳设置文档属性,该时间戳将执行IP脚本。 this is the most solid implementation. 这是最可靠的实现。

otherwise, you can try something like this: 否则,您可以尝试如下操作:

// get a reference to a container on the page with an ID "hidden"
var $hidden = $("#hiddenBtn input");

// only continue if the container is empty
if !($hidden.text()) {
    var now = Date.now();
    $hidden.text(now)
           .focus()
           .blur();
|}

this is essentially the same as the code you posted, but instead of relying on the var n , you're counting on the input #hiddenBtn > input being empty. 这基本上与您发布的代码相同,但是您无需依靠var n ,而是依靠输入#hiddenBtn > input为空。 there is a caveat that you'll have to ensure this field is empty before you save the document 请注意,在保存文档之前,必须确保此字段为空

one addtional solution is using a Data Function to update the document property, like @user1247722 shows in his answer here: https://stackoverflow.com/a/40712635/4419423 另一种解决方案是使用数据功能更新文档属性,如@ user1247722在其答案中所示: https ://stackoverflow.com/a/40712635/4419423

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM