問題描述
我正在嘗試在 React JS 中嵌入 Power BI 報表,我想嵌入報表并讓報表實例進一步使用它.我正在使用 Power BI 反應擴展來反應嵌入報告,但我不斷收到無法讀取未定義的屬性嵌入"的錯誤.
I am trying to embed a Power BI report in React JS and I would like to embed the report and get the report instance to work further with it. I am using Power BI react extension in react to embed the report but I keep getting an error that Cannot read property 'embed' of undefined.
索引.js
import { powerbi, models, embed } from "powerbi-client";
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
function ReportBI() {
let token ="abcExample";
let embedUrlBi = "https://app.powerbi.com/reportEmbed";
let reportId = "ReportID";
const embedConfig = {
type: "report",
id: reportId,
embedUrl: embedUrlBi,
accessToken: token,
tokenType: models.TokenType.Embed
};
function test() {
var embedContainer = document.getElementById("container");
var report = powerbi.embed(embedContainer, embedConfig);
console.log(report);
}
useEffect(() => {
test();
});
return (
<>
<div id="container"></div>
</>
);
}
const element = <ReportBI />;
ReactDOM.render(element, document.getElementById("root"));
索引.Html
<div id="root">
<div id="container"></div>
</div>
我試圖在嵌入報表后獲取它的實例以使用它做其他事情.我可以這樣做嗎?
I am trying to get instance of the report after embedding it to do other things with it. Can I do this?
推薦答案
你可以試試新的 powerbi-client-react 用于在 React 應用程序中嵌入 PowerBI 實體的庫
You may try the new powerbi-client-react library for embedding PowerBI entities in React applications
"getEmbeddedComponent"prop 返回嵌入式 PowerBI 報表的實例
The "getEmbeddedComponent" prop returns the instance of embedded PowerBI report
這篇關于在 React JS 中嵌入 Power BI 報表以獲取報表實例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!