嵌入式Power BI报告中无法获取report.getPages的报告

4
尝试在.Net MVC应用程序中获取嵌入式Power BI报告的可视化效果时,我从嵌入式Power BI Playground网站尝试了下面提到的代码。 但是,我无法获得可视化效果。 在调试时,我可以看到报告的getPages属性的值为:

getPages: ƒ ()arguments: null caller: null length: 0 name: ""

此外,console.log(report.getPages()); 的输出结果为

[[PromiseStatus]]: "pending" [[PromiseValue]]: undefined

以下是我尝试的代码:

// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];

// Get a reference to the embedded report.
report = powerbi.get(embedContainer);

// Retrieve the page collection and get the visuals for the first page.
report.getPages()
    .then(function (pages) {
        // Retrieve active page.
        var activePage = pages.filter(function (page) {
            return page.isActive
        })[0];

        activePage.getVisuals()
            .then(function (visuals) {
                Log.log(
                    visuals.map(function (visual) {
                        return {
                            name: visual.name,
                            type: visual.type,
                            title: visual.title,
                            layout: visual.layout
                        };
                    }));
            })
            .catch(function (errors) {
                Log.log(errors);
            });
    })
    .catch(function (errors) {
        Log.log(errors);
    });
1个回答

8
您可能面临时序问题。使用PowerBI事件处理程序,在确保报告已完全加载、呈现和可用之前,不要应用更改。为此,您可以利用渲染事件。https://github.com/Microsoft/PowerBI-JavaScript/wiki/Handling-Events。下面是一个示例:获取页面、从页面获取可视化对象,并从可视化对象中导出数据。
var report = powerbi.embed(reportContainer, config);

report.on("rendered", function (event) {
  // do stuff here like get pages, export data, apply filters or whatever it is you want to do to manipulate the report

  report.getPages().then((pages) => {
    pages[0].getVisuals().then((visuals) => (d = visuals));
  });

  var v = d[1].exportData(models.ExportDataType.Summarized, 100);
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接