![](/img/trans.png)
[英]How to run an IronPython Script on Spotfire Dashboard load
[英]Spotfire - javascript to trigger IronPython script to be executed on report load
我有下面的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});
請讓我知道是否需要更多信息。 提前致謝!!!
我有多次執行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
為空。 請注意,在保存文檔之前,必須確保此字段為空
另一種解決方案是使用數據功能更新文檔屬性,如@ user1247722在其答案中所示: https ://stackoverflow.com/a/40712635/4419423
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.