angular - 获取嵌入式 power bi 报告的所有页面
问题描述
我正在开发 Angular 4 中的嵌入式 Power Bi 应用程序。该应用程序将多个报告(存储在 Azure 上)分组,我想检索每个报告的所有页面,而无需将其加载到容器中。power bi api 显然不允许这样做;有办法吗?
解决方案
我知道它已经很晚了,但可能对像我这样寻找一些代码片段的其他人有用以下获取所有报告页面并创建按钮以将它们嵌入到不同的页面上。
请注意,这是来自 ASP.NET CORE MVC,我可以从提供的模型中呈现我的安全嵌入信息。
希望这可以帮助...
$(document).ready(function () {
var preloadElement = powerbi.preload({
type: "report",
baseUrl: "https://embedded.powerbi.com/reportEmbed",
});
$(preloadElement).on("preloaded", function () {
setupEnhancedReportLinks(
"#enhanced-report-container",
@Json.Serialize(Model.EnhancedReports)
);
});
});
function setupEnhancedReportLinks(containerName, reportsModel) {
$.each(reportsModel, function () {
const config = {
type: "report",
id: this.id,
embedUrl: this.embedUrl,
accessToken: this.embedToken.token,
tokenType: models.TokenType.Embed,
permissions: models.Permissions.All,
viewMode: models.ViewMode.View,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: false,
},
};
let elements = [];
elements.push(
$("<h4> ")
.attr({ id: `title-for-${config.id}` })
.text(this.displayName)
);
elements.push($("<div>").attr({ id: `buttons-for-${config.id}` }));
// Note this element is hidden; loading a report still requires a page element to contain it, so we hide it on creation
elements.push(
$("<div>")
.attr({ id: `report-for-${config.id}` })
.hide()
);
// add all report information into the main dom element
$(containerName).append(
$("<div>")
.attr({ id: `container-for-${config.id}`, class: "well col-lg-12" })
.append(elements)
);
// Load the report
// fetch, then iterate the pages to create the buttons which are added to the report's button container
var report = powerbi.load($(`#report-for-${config.id}`)[0], config);
report.on("loaded", function () {
report.getPages().then(function (pages) {
$.each(pages, function () {
console.log("is this a page", this, config);
$(`#buttons-for-${config.id}`).append(
$("<a>")
.text(this.displayName)
.attr({
href: `/EmbeddedReport/EmbedReport?reportId=${config.id}&reportSection=${this.name}`,
class: "enh-button",
})
);
});
});
});
});
}
推荐阅读
- c++ - 将函数应用于元组中的每个元素,将每个元素转换为类型包中的不同类型,然后作为参数包传递
- string - 如何获取 DolphinDB 数据库中某个模式左侧的字符串部分
- c++ - SFINAE 和标签调度的区别
- sql - 如何将聚合数据“取消分组”到行?
- azure - AzurePowershell 任务找不到 Profile.ps1
- angular - 如何在结构指令中将函数传递给 createEmbeddedView?
- subprocess - 子进程未使用 pytest 运行 Sikuli
- asp.net-core-mvc - 与 ASP.Net、EF、数据库优先的模型绑定安全
- python - 使用 Python 运行外部可执行程序
- python-3.x - tkinter 复选框选择在功能中不起作用