问题描述
我正在尝试在 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 = "http://www.51sjk.com/Upload/Articles/1/0/334/334157_20221025103405503.jpg 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