Javascript 未捕获(承诺中)类型错误:无法读取属性';ui5和x27;未定义的
当我尝试在js视图选项卡中创建条形图时,它会给我这个错误。 这是我的html代码Javascript 未捕获(承诺中)类型错误:无法读取属性';ui5和x27;未定义的,javascript,html,sapui5,Javascript,Html,Sapui5,当我尝试在js视图选项卡中创建条形图时,它会给我这个错误。 这是我的html代码 <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/> <link rel="styles
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<link rel="stylesheet" type="text/css" href="Styles/MainPage.css"/>
<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m, sap.viz"
data-sap-ui-theme="sap_bluecrystal">
</script>
<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->
<script>
sap.ui.localResources("empcrud");
//sap.ui.localResources("Styles");
var app = new sap.m.App("AppId", { initialPage: "idEMainPage1" });
var page = sap.ui.view({ id: "idEmpDetails1", viewName: "empcrud.EmpDetails", type: sap.ui.core.mvc.ViewType.JS });
var page1 = sap.ui.view({ id: "idEMainPage1", viewName: "empcrud.MainPage", type: sap.ui.core.mvc.ViewType.JS });
var page2 = sap.ui.view({ id: "idGrafPage1", viewName: "empcrud.Grafik", type: sap.ui.core.mvc.ViewType.JS });
app.addPage(page).addPage(page1).addPage(page2);
app.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
当我尝试在html脚本中粘贴视图代码时,它可以正常工作,在xml视图中也可以。我认为这是关于js视图和html之间的连接。但是view看不到sap.viz。有没有办法在js中定义sap.viz,或者如何克服这个问题
谢谢。问题在于sapui库,只需添加在线核心库即可正常工作。
“@İbrahimÖzcan您的
index.html
缺少sap.ui.getCore().attachInit()
。请参阅中的我的答案。从哪个src
引导UI5并不重要。真正的问题是,您试图在不等待依赖库(sap.viz
)完全加载的情况下访问该类。看见
var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions: [
{
axis: 1,
name: 'Uname',
value: "{Uname}"
}
],
measures: [
{
name: 'Modno',
value: '{Modno}'
},
],
data: {
path: "/results"
}
});
var oBarChart = new sap.viz.ui5.Bar({
width: "80%",
height: "400px",
plotArea: {
//'colorPalette' : d3.scale.category20().range()
},
title: {
visible: true,
text: 'Modno Grafiği'
},
dataset: oDataset
});