2017-02-24 3 views
0

私はsapui5が新しく、Initメソッドで関数を呼び出す方法を知りたいですか?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(); 

    } 

任意の提案ですか?

答えて

1

私はあなたがほとんどinitから関数を呼び出すことがあると思います。

onInit: function() { 
    ... 
    this.handleSelectDialogPress(); 
} 

handleSelectDialogPress : function() { 
    // some code 
} 

参照してください:あなたは同じコントローラ内にあるいくつかの関数を呼び出すにしたいならば、「この」キーワード(ここでは「この」は、現在のコントローラを参照)をを使用する例については

、コードの下には、いくつかの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); 
     } 
    }); 
}); 

MyUtils

sap.ui.define([], function() { 
    "use strict"; 

    return { 
     myFunc: function(input) { 
     // some code 
     } 
    }; 
}); 
関連する問題