简体   繁体   English

Tableau Javascript API workbook.activeSheet()

[英]Tableau Javascript API workbook.activeSheet()

I'm probably missing something very obvious here but why does the following not write anything to the log? 我可能在这里遗漏了一些非常明显的东西,但是为什么以下内容没有在日志中写入任何内容? (jsfiddle here - http://jsfiddle.net/hiwilson1/qk9cjuh2/ - although it's not working for me) (这里的jsfiddle- http://jsfiddle.net/hiwilson1/qk9cjuh2/-尽管它不适用于我)

<html>
<head>
<style>
#tableauViz {
    width: 1500px;
    height: 500px;
}
input[type="button"] {
    margin: 5px;
}
</style>
<script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau-2.0.0.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
window.onload = function() {

    // append visualisation container
    d3.select("body").append("div").attr("id", "tableauViz")

    // function to build visualisation.
    function initializeViz() {
        var placeholderDiv = document.getElementById("tableauViz");
        var url = "http://public.tableau.com/views/WorldIndicators/GDPpercapita";
        var options = {
            width: placeholderDiv.offsetWidth,
            height: placeholderDiv.offsetHeight,
            hideTabs: false,
            hideToolbar: true,
            onFirstInteractive: function () {
                workbook = viz.getWorkbook();
                activeSheet = workbook.getActiveSheet();
            }
        };
        viz = new tableau.Viz(placeholderDiv, url, options);
    }  

    initializeViz();

    // switch worksheet function.
    function switchTab(val) {
        workbook.activateSheetAsync(val);
    }    

    d3.select("body").append("input")
        .attr("type", "button")
        .attr("value", "click me")
        .on("click", function() {switchTab("GDP per capita map")})

    console.log(workbook.activeSheet)
}
</script>
</head>

<body>

</body>
</html>

I've built the visualization and then rigged up a button to run a small function that changes worksheet. 我已经建立了可视化,然后装配了一个按钮来运行一个小的功能来更改工作表。 I can access the workbook object from within that function but there's nothing special about the function that gives it the right to access that workbook object. 我可以从该函数中访问该工作簿对象,但是该函数没有什么特别的授予它访问该工作簿对象的权限。 Why can I not also output info about the workbook object to the log? 为什么我也不能将有关工作簿对象的信息输出到日志?

The error I receive is 'Reference Error: Workbook is not defined'. 我收到的错误是“参考错误:未定义工作簿”。 If it's not defined how can the function use it?! 如果未定义,函数如何使用它?

Your workbook variable is not created until the onFirstInteractive callback is called, but your call to console.log() is immediately after initializing your tableau.Viz . 在调用onFirstInteractive回调之前,不会创建workbook变量,但是在初始化tableau.Viz之后立即调用console.log() The act of initializing that object won't cause the callback to be called - that will happen later. 初始化该对象的行为不会导致调用回调-稍后会发生。

Depending on the reason you're calling console.log like that, it might make sense to move that call to the end of the onFirstInteractive callback. 根据您这样调用console.log的原因,将调用移到onFirstInteractive回调的末尾可能很有意义。

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

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