2016-11-23 65 views
0

我有下面的JavaScript代码,它会在加载报表时触发IronPython脚本。Spotfire-javascript来触发IronPython脚本在报表加载时执行

我唯一的问题是,有一个原因,我不知道它(它会触发脚本)几次。

有人能帮助我吗?以下是脚本:

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}); 

请让我知道你是否需要更多信息。 在此先感谢!

回答

1

我有多次执行Javascript的类似问题。 Spotfire似乎不止一次地实例化JS,并且它可以引起一些有趣的行为...

最好的解决方案,在我看来,只有当用户通过链接访问文档时才有效(而不是浏览库)。通过一个配置块来设置一个文档属性和当前时间戳,这将执行你的IP脚本。这是最坚实的实施。

否则,你可以尝试这样的事:

// 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(); 
|} 

这本质上是一样的,你发布的代码,但不是依靠VAR n,你在是输入#hiddenBtn > input计数空。还有一个需要注意的是,你必须确保你保存文档之前,此字段为空

一个addtional解决方案是使用数据功能来更新文档属性,像@ user1247722显示了他的答案在这里:https://stackoverflow.com/a/40712635/4419423

+0

嗨niko,我试过你的solucion,但没有奏效。我也改变了一点脚本://只在容器为空时继续 var texts = $('#hiddenBtn input')。val(); if(texts ===“”){ \t var now = new Date(); \t $('#hiddenBtn input')。val(now.getTime()); \t $('#hiddenBtn input')。focus(); \t $('#hiddenBtn input')。blur(); } – thundermils