获取嵌入式 power bi 报表的所有页面
Get all pages of a embedded power bi report
我正在 angular 4 中开发嵌入式 power bi 应用程序。
此应用程序将多个报告(存储在 Azure 上)分组,我想检索每个报告的所有页面,而不必将其加载到容器中。 power bi api 显然不允许这样做;有办法吗?
遗憾的是,使用 Power BI 当前的 REST API 无法做到这一点。
您可能需要使用 preload
(或热启动)来加载报告的元数据,而不必将其呈现到屏幕上。
有关详细信息,请参阅此处:
https://github.com/Microsoft/PowerBI-JavaScript/wiki/Phased-Embedding-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",
})
);
});
});
});
});
}
我正在 angular 4 中开发嵌入式 power bi 应用程序。 此应用程序将多个报告(存储在 Azure 上)分组,我想检索每个报告的所有页面,而不必将其加载到容器中。 power bi api 显然不允许这样做;有办法吗?
遗憾的是,使用 Power BI 当前的 REST API 无法做到这一点。
您可能需要使用 preload
(或热启动)来加载报告的元数据,而不必将其呈现到屏幕上。
有关详细信息,请参阅此处: https://github.com/Microsoft/PowerBI-JavaScript/wiki/Phased-Embedding-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",
})
);
});
});
});
});
}