Power Bi JavaScript 仪表板嵌入配置
PowerBi JavaScript dashboard embedConfiguration
我想使用 this GitHub 示例代码中的 JavaScript 将我的 PowerBi 仪表板嵌入到 HTML 文件中。我收到的错误是:
Unable to get property 'models' of undefined or null reference
我是否缺少需要添加到头部部分的 .js
文件?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>`
<script>
$(document).ready(function () {
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
var embedConfiguration = {
type: 'dashboard',
id: 'dashboardid',
embedUrl: 'https://app.powerbi.com/reportEmbed',
tokenType: models.TokenType.Aad,
accessToken: 'TokenKey'
};
var $dashboardContainer = $('#embedContainer');
var dashboard = powerbi.embed($dashboardContainer.get(0), embedConfiguration);
});
</script>
</head >
<body>
<div id="dashboardContainer"></div>
</body >
</html >
您需要包含 ECMAScript 6 (ES6):
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.js"></script>
您还需要加载实际的 PowerBi 库以及任何必要的 JS 文件,因为您似乎并没有这样做,至少在您提供的代码中是这样。
您还为变量 $dashboardContainer
分配了 $('#embedContainer')
的值,这不是您提供的 HTML 中的一个元素。您在 HTML.
中使用了 #dashboardContainer
的 ID
你可以试试,
<script src="https://raw.githubusercontent.com/Microsoft/PowerBI-JavaScript/master/dist/powerbi.js"></script>
我想使用 this GitHub 示例代码中的 JavaScript 将我的 PowerBi 仪表板嵌入到 HTML 文件中。我收到的错误是:
Unable to get property 'models' of undefined or null reference
我是否缺少需要添加到头部部分的 .js
文件?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>`
<script>
$(document).ready(function () {
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
var embedConfiguration = {
type: 'dashboard',
id: 'dashboardid',
embedUrl: 'https://app.powerbi.com/reportEmbed',
tokenType: models.TokenType.Aad,
accessToken: 'TokenKey'
};
var $dashboardContainer = $('#embedContainer');
var dashboard = powerbi.embed($dashboardContainer.get(0), embedConfiguration);
});
</script>
</head >
<body>
<div id="dashboardContainer"></div>
</body >
</html >
您需要包含 ECMAScript 6 (ES6):
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.js"></script>
您还需要加载实际的 PowerBi 库以及任何必要的 JS 文件,因为您似乎并没有这样做,至少在您提供的代码中是这样。
您还为变量 $dashboardContainer
分配了 $('#embedContainer')
的值,这不是您提供的 HTML 中的一个元素。您在 HTML.
#dashboardContainer
的 ID
你可以试试,
<script src="https://raw.githubusercontent.com/Microsoft/PowerBI-JavaScript/master/dist/powerbi.js"></script>