javascript - 未在 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);
});
解决方案
你有时间问题。使用 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);
});
推荐阅读
- django - 缓存 django 查询集的 id 列表,并将该列表重用于另一个视图集
- java - 在 Spring Boot(云应用程序)中无法连接到 Oracle DB
- python - 扩展 markdown jupyter nbconvert 模板以删除代码块,但保留代码块的 markdown 输出
- python - Pygame 没有响应
- java - 如何使用 maven 部署 de-Lombok-ed 源
- outlook-web-addins - Outlook 插件可以跟踪电子邮件的阅读状态吗?
- javascript - Flutter setState 在使用 Navigator.push 时弹出页面,而在使用 Navigator.of 时它根本不起作用
- windows - 调用批处理文件运行后其余脚本未运行?
- laravel - 为什么我的 livewire.js 连接出现 404 错误?
- android - RecyclerView 选择库 - 点击太快让点击传递到我的 OnClickListener