-1
我想在sapui5應用程序中顯示一個消息器,當onSave被打印或者init函數啓動時。但是我在控制檯中總是出現錯誤,而messageToast不起作用。sapui5,MessageToast.show不是一個函數,雖然sap/m/MessageToast已經被導入
ERRORMESSAGE控制檯: 未捕獲的(以諾)類型錯誤:MessageToast.show不是一個函數
這是我controller.js:
sap.ui.define(['sap/ui/core/mvc/Controller',
\t 'timeTrackertimeTracker/controller/BaseController',
\t 'sap/ui/model/json/JSONModel',
\t "sap/m/MessageToast",
\t "sap/ui/model/odata/ODataModel",
\t "sap/ui/core/routing/History"
\t ],
\t function(Controller, BaseController, MessageToast, JSONModel, ODataModel, History) {
\t "use strict";
\t //Global variables
\t //var _oController, oModel, oView;
\t var Calendarcontroller = BaseController.extend("timeTrackertimeTracker.controller.Calendarform", {
\t
\t \t /* =========================================================== */
\t \t /* lifecycle methods */
\t \t /* =========================================================== */
\t \t
\t \t onInit: function() {
\t \t \t \t //Store controller reference to global variable
\t \t \t \t this.getRouter().getRoute("Calendarform").attachPatternMatched(this._onRouteMatched, this);
\t \t \t \t MessageToast.show("init");
\t \t },
\t \t \t \t
\t \t
\t \t /* =========================================================== */
\t \t /* event handlers */
\t \t /* =========================================================== */
\t \t
\t \t _onRouteMatched: function() {
\t \t \t // register for metadata loaded events
\t \t \t var oModel = this.getModel("appointments");
\t \t \t oModel.metadataLoaded().then(this._onMetadataLoaded.bind(this));
\t \t },
\t \t
\t \t _onMetadataLoaded: function() {
\t \t \t // create default properties
\t \t \t var oProperties = {
\t \t \t \t Id: "Id" + parseInt(Math.random() * 1000000000)
/* \t \t \t \t duration: "",
\t \t \t \t resttime: "",
\t \t \t \t title: "",
\t \t \t \t starttime: "",
\t \t \t \t endtime: "",
\t \t \t \t Description: ""*/
\t \t \t };
\t \t \t // create new entry in the model
\t \t \t this._oContext = this.getModel("appointments").createEntry("/appointments", {
\t \t \t \t properties: oProperties
\t \t \t \t ,
\t \t \t \t success: this._onCreateSuccess.bind(this)
\t \t \t });
\t \t \t // bind the view to the new entry
\t \t \t this.getView().setBindingContext(this._oContext, "appointments");
\t \t \t
\t \t },
\t \t
\t \t onSave: function(oEvent) {
\t \t \t
\t \t \t // bind the view to the new entry
\t \t \t //this.getView().setBindingContext(this._oContext);
\t \t \t this.getModel("appointments").submitChanges();
\t \t
\t \t },
\t \t
\t \t _onCreateSuccess: function (oEvent) {
\t \t \t // navigate to the new product's object view
\t \t \t this.getRouter().navTo("AppointmentsList", true);
\t
\t \t \t // unbind the view to not show this object again
\t \t \t this.getView().unbindObject();
\t \t \t
\t \t \t // show success messge
/* \t \t \t var sMessage = this.getResourceBundle().getText("newObjectCreated", [ oEvent.Id ]);
\t \t \t MessageToast.show(sMessage, {
\t \t \t \t closeOnBrowserNavigation : false
\t \t \t });*/
\t \t },
\t \t
/* \t \t _onCreateSuccess: function (oAppointment) {
\t \t \t // show success messge
\t \t \t var sMessage = this.getResourceBundle().getText("newObjectCreated", [ oAppointment.Title ]);
\t \t \t MessageToast.show(sMessage, {
\t \t \t \t closeOnBrowserNavigation : false
\t \t \t });
\t \t },
\t \t */
\t \t onCancel: function() {
\t \t \t this.onNavBack();
\t \t \t //this.getView().getModel("appointments").deleteCreatedEntry(this._oContext);
\t \t },
\t \t
\t \t
\t \t /**
\t \t * Event handler for navigating back.
\t \t * It checks if there is a history entry. If yes, history.go(-1) will happen.
\t \t * If not, it will replace the current entry of the browser history with the worklist route.
\t \t * @public
\t \t */
\t \t onNavBack : function() {
/* \t \t \t var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
\t \t \t oRouter.navTo("AppointmentsList");*/
\t \t \t
\t \t \t
\t \t \t var oHistory = History.getInstance(),
\t \t \t \t sPreviousHash = oHistory.getPreviousHash();
\t \t \t // discard new product from model.
\t \t \t this.getModel("appointments").deleteCreatedEntry(this._oContext);
\t \t \t if (sPreviousHash !== undefined) {
\t \t \t \t // The history contains a previous entry
\t \t \t \t history.go(-1);
\t \t \t } else {
\t \t \t \t // Otherwise we go backwards with a forward history
\t \t \t \t var bReplace = true;
\t \t \t \t this.getRouter().navTo("AppointmentsList", {}, bReplace);
\t \t \t }
\t \t }
\t });
\t return Calendarcontroller;
});
這工作,謝謝 – user3753271