Javascript 如何在Init方法中调用函数?

Javascript 如何在Init方法中调用函数?,javascript,sapui5,Javascript,Sapui5,我是sapui5新手,我想知道如何在我的Init方法中调用函数 我目前拥有的代码如下: onInit: function() { this.oInitialLoadFinishedDeferred = jQuery.Deferred(); var oEventBus = this.getEventBus(); this.getView().byId("list").attachEventOnce("updateFini

我是sapui5新手,我想知道如何在我的Init方法中调用函数

我目前拥有的代码如下:

onInit: function() { 

        this.oInitialLoadFinishedDeferred = jQuery.Deferred();          
        var oEventBus = this.getEventBus();



        this.getView().byId("list").attachEventOnce("updateFinished", function() {
            this.oInitialLoadFinishedDeferred.resolve();
            oEventBus.publish("Master", "InitialLoadFinished", {
                oListItem: this.getView().byId("list").getItems()[0]
            });
        }, this);

        oEventBus.subscribe("Detail", "TabChanged", this.onDetailTabChanged, this);

        //on phones, we will not have to select anything in the list so we don't need to attach to events
        if (Device.system.phone) {
            return;
        }


        this.getRouter().attachRoutePatternMatched(this.onRouteMatched, this);

        oEventBus.subscribe("Detail", "Changed", this.onDetailChanged, this);
        oEventBus.subscribe("Detail", "NotFound", this.onNotFound, this);
        oEventBus.subscribe("Detail", "Cancelled", this.onDetailChangeCancelled, this);

        // this.handleSelectDialogPress();

    }   

有什么建议吗?

我想您差不多可以从init调用函数了

例如,如果要调用同一控制器中的某个函数,请使用'this'关键字(此处'this'指当前控制器):

如果您想调用某些Utils.js中的函数,请参阅下面的代码

ControllerName.controller.js

sap.ui.define([
   "sap/ui/core/mvc/Controller",
   "./MyUtils"
], function(Controller, MyUtils) {
   "use strict";

   return Controller.extend("your.controller.ControllerName", {
      myFunc2: function(input) {
         MyUtils.myFunc(input);
      }
   });
});
sap.ui.define([], function() {
   "use strict";

   return {
      myFunc: function(input) {
         // some code
      }
   };
});
MyUtils

sap.ui.define([
   "sap/ui/core/mvc/Controller",
   "./MyUtils"
], function(Controller, MyUtils) {
   "use strict";

   return Controller.extend("your.controller.ControllerName", {
      myFunc2: function(input) {
         MyUtils.myFunc(input);
      }
   });
});
sap.ui.define([], function() {
   "use strict";

   return {
      myFunc: function(input) {
         // some code
      }
   };
});