Javascript 从视图调用SAPUI5控件有效,嵌入在XMLComposite控件中则无效(全局外部库)
我试图构建一个amCharts容器控件,一个UI5控件,通过amCharts构建图形。一般来说,它是有效的,但我相信你可以发现很多可以做得更好的黑客 目前我最大的问题是,当我从另一个XMLComposite控件中使用该控件时,会出现错误 未捕获引用错误:未在f.onAfterRendering定义am4core (AmChartContainer.js?eval:38) 调试代码证明jQuery.sap.includeDescript在之前执行过,但全局元素am4core仍然不可用。当我将控件直接嵌入到视图中时,它仍然可以工作 另一件我不满意的事情是活动顺序。希望在render方法中实例化amchart,但此时没有amchart实例化所需的htmlelement。同意吗 如果有任何建议,我将不胜感激Javascript 从视图调用SAPUI5控件有效,嵌入在XMLComposite控件中则无效(全局外部库),javascript,sapui5,amcharts,Javascript,Sapui5,Amcharts,我试图构建一个amCharts容器控件,一个UI5控件,通过amCharts构建图形。一般来说,它是有效的,但我相信你可以发现很多可以做得更好的黑客 目前我最大的问题是,当我从另一个XMLComposite控件中使用该控件时,会出现错误 未捕获引用错误:未在f.onAfterRendering定义am4core (AmChartContainer.js?eval:38) 调试代码证明jQuery.sap.includeDescript在之前执行过,但全局元素am4core仍然不可用。当我将控件直
sap.ui.define([ 'sap/ui/core/Control', "jquery.sap.global" ], function(Control, jQuery) {
return Control.extend("io.rtdi.amChartContainer", {
metadata: {
properties: {
width: {
type: "sap.ui.core.CSSSize",
defaultValue: "100%"
},
height: {
type: "sap.ui.core.CSSSize",
defaultValue: "100%"
},
plugin: {
type: "string"
}
},
aggregations : {},
},
renderer : function(oRm, oControl) {
oRm.write("<div");
oRm.write(" style=\"width: " + oControl.getWidth() +
"; height: " + oControl.getHeight() + ";\" ");
oRm.writeControlData(oControl);
oRm.write(">");
oRm.write("</div>");
},
onBeforeRendering : function() {
jQuery.sap.includeScript("https://www.amcharts.com/lib/4/core.js",
"amCharts.core", null, null);
jQuery.sap.includeScript("https://www.amcharts.com/lib/4/charts.js",
"amCharts.charts", null, null);
if (!!this.getPlugin()) {
jQuery.sap.includeScript(
"https://www.amcharts.com/lib/4/" + this.getPlugin(),
"amCharts.plugin", null, null);
}
},
onAfterRendering : function() {
// if I need to do any post render actions, it will happen here
if (sap.ui.core.Control.prototype.onAfterRendering) {
sap.ui.core.Control.prototype.onAfterRendering.apply(this, arguments);
}
this._chart = am4core.create(this.getId(), am4plugins_forceDirected.ForceDirectedTree);
},
getChart: function() {
return this._chart;
}
});
});
sap.ui.define(['sap/ui/core/Control','jquery.sap.global',函数(Control,jquery){
return Control.extend(“io.rtdi.amChartContainer”{
元数据:{
特性:{
宽度:{
类型:“sap.ui.core.CSSSize”,
默认值:“100%”
},
高度:{
类型:“sap.ui.core.CSSSize”,
默认值:“100%”
},
插件:{
类型:“字符串”
}
},
聚合:{},
},
渲染器:函数(oRm、oControl){
oRm.写(“”);
oRm.写(“”);
},
onbeforeredering:function(){
jQuery.sap.includeDescript(“https://www.amcharts.com/lib/4/core.js",
“amCharts.core”,空,空);
jQuery.sap.includeDescript(“https://www.amcharts.com/lib/4/charts.js",
“amCharts.charts”,空,空);
如果(!!this.getPlugin()){
jQuery.sap.includeScript(
"https://www.amcharts.com/lib/4/“+this.getPlugin(),
“amCharts.plugin”,null,null);
}
},
onAfterRendering:函数(){
//如果我需要执行任何渲染后操作,将在此处执行
if(sap.ui.core.Control.prototype.onAfterRendering){
sap.ui.core.Control.prototype.onAfterRendering.apply(这是参数);
}
this.\u chart=am4core.create(this.getId(),am4plugins\u forceDirected.ForceDirectedTree);
},
getChart:function(){
返回此。\u图表;
}
});
});
首先,请使用jQuery.sap.includeScript,因为jQuery.sap.includeScript被认为不推荐使用
您没有定义任何fnLoadCallback。在调用onAfterRendering时,是否100%确定已加载脚本并定义了am4core 开头的全局关键字似乎是缺少的部分:
/* global am4core:true */
/* global am4charts:true */
sap.ui.define([
"sap/ui/core/mvc/Controller",...