Я новичок в технологиях SAP, у меня проблема с маршрутизацией SAPUI5 в Eclipse IDE, я разработал скетч на платформе сборки, скопировал и вставил код с платформы сборки в свой проект Eclipse, но в Eclipse я иметь эту проблему this.getOwnerComponent (...) не определено , проблема в var oBindingContext = oEvent.getSource (). getBindingContext (); . Если я тестирую свой скетч в сети, то он работает, но в Eclipse нет.
Мне нужно изменить страницу, когда кто-то нажимает на кнопку, это часть кода .... спасибо заранее:
sap.ui.define( ["sap/ui/core/mvc/Controller",
"sap/m/MessageBox",
"sap/ui/core/routing/History"
], function (Controller,MessageBox, History) {
"use strict";
return Controller.extend("sap.ui.core.sample.TargetsStandalone.targetsApp.controller.login", {
onToView2 : function () {
_onGenericTilePress();
sap.ui.core.BusyIndicator.hide();
},
handleRouteMatched: function(oEvent) {
var sAppId = "xxx";
var oParams = {};
if (oEvent.mParameters.data.context) {
this.sContext = oEvent.mParameters.data.context;
} else {
if (this.getOwnerComponent().getComponentData()) {
var patternConvert = function(oParam) {
if (Object.keys(oParam).length !== 0) {
for (var prop in oParam) {
if (prop !== "sourcePrototype" && prop.includes("Set")) {
return prop + "(" + oParam[prop][0] + ")";
}
}
}
};
this.sContext = patternConvert(this.getOwnerComponent().getComponentData().startupParameters);
}
}
var oPath;
if (this.sContext) {
oPath = {
path: "/" + this.sContext,
parameters: oParams
};
this.getView().bindObject(oPath);
}
},
_onPageNavButtonPress: function(oEvent) {
var oBindingContext = oEvent.getSource().getBindingContext();
return new Promise(function(fnResolve) {
this.doNavigate("Products", oBindingContext, fnResolve, "");
}.bind(this)).catch(function(err) {
if (err !== undefined) {
MessageBox.error(err.message);
}
});
},
doNavigate: function(sRouteName, oBindingContext, fnPromiseResolve, sViaRelation) {
alert(sRouteName + oBindingContext);//FLAG
var sPath = (oBindingContext) ? oBindingContext.getPath() : null;
var oModel = (oBindingContext) ? oBindingContext.getModel() : null;
var sEntityNameSet;
if (sPath !== null && sPath !== "") {
if (sPath.substring(0, 1) === "/") {
sPath = sPath.substring(1);
}
sEntityNameSet = sPath.split("(")[0];
}
var sNavigationPropertyName;
var sMasterContext = this.sMasterContext ? this.sMasterContext : sPath;
alert(sPath); //FLAG
if (sEntityNameSet !== null) {
sNavigationPropertyName = sViaRelation || this.getOwnerComponent().getNavigationPropertyForNavigationWithContext(sEntityNameSet, sRouteName);
}
if (sNavigationPropertyName !== null && sNavigationPropertyName !== undefined) {
if (sNavigationPropertyName === "") {
this.oRouter.navTo(sRouteName, {
context: sPath,
masterContext: sMasterContext
}, false);
} else {
oModel.createBindingContext(sNavigationPropertyName, oBindingContext, null, function(bindingContext) {
if (bindingContext) {
sPath = bindingContext.getPath();
if (sPath.substring(0, 1) === "/") {
sPath = sPath.substring(1);
}
} else {
sPath = "undefined";
}
// If the navigation is a 1-n, sPath would be "undefined" as this is not supported in Build
if (sPath === "undefined") {
this.oRouter.navTo(sRouteName);
} else {
this.oRouter.navTo(sRouteName, {
context: sPath,
masterContext: sMasterContext
}, false);
}
}.bind(this));
}
} else {
this.oRouter.navTo(sRouteName);
}
if (typeof fnPromiseResolve === "function") {
fnPromiseResolve();
}
},
_onGenericTilePress: function(oEvent) {
var oBindingContext = oEvent.getSource().getBindingContext();
alert("1");
var oSource = oEvent.getSource();
alert(oSource);
var oBind = oSource.getBindingContext();
alert(oBind);
var sPath = oBind.getPath();
alert(sPath);
alert(oSource+" "+oBind+" "+sPath);
alert(oBindingContext);//FLAG
return new Promise(function(fnResolve) {
this.doNavigate("dashboard", oBindingContext, fnResolve, "");
}.bind(this)).catch(function(err) {
if (err !== undefined) {
MessageBox.error(err.message);
}
});
}
});
}, /* bExport= */ true);