首页 > 解决方案 > 未在 Embedded Power BI 报告中获取 report.getPages

问题描述

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

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

还有console.log(report.getPages());

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

PF 我试过的代码:

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

标签: javascriptpowerbipowerbi-embedded

解决方案


你有时间问题。使用 PowerBI 事件处理程序并且不要对报表应用更改,除非您知道报表已完全加载、呈现且可用。为此,您可以确保 Rendered 事件。

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

推荐阅读