2016-11-23 68 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