2016-09-27 23 views
1

objectルートをメインルート(テーブルページ)に追加しますが、this.getRouter is not a functionエラーを返します。メインコントローラで未知のタイプエラー:this.getRouterは関数ではありません

Component.jsで
onPress : function(oEvent) { 
     this._showObject(oEvent.getSource()); 
    }, 

    _showObject : function (oItem) { 
     this.getRouter().navTo("object", { 
      objectId: oItem.getBindingContext().getProperty("task_id") 
     }); 
    }, 

(私がチェックしました、それがすでにロードされています、エラーが生成されない)

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

    return UIComponent.extend("cts.mobile.Component", { 
     metadata : { 
      rootView : "cts.mobile.view.TaskTest", 
      routing : { 
       "config": { 
        "routerClass": "sap.m.routing.Router", 
        "viewType": "XML", 
        "viewPath": "cts.mobile.view", 
        "controlId": "taskapp", //in task.view.xml 
        "controlAggregation": "pages", 
        "async": true 
       }, 
       "routes": [ 
        { 
         "pattern": "", 
         "name": "task", 
         "target": "task" 
        }, 
        { 
         "pattern": "ProductCollection/{objectId}", 
         "name": "object", 
         "target": "object" 
        } 
       ], 
       "targets": { 
        "worklist": { 
         "viewName": "TaskTest", 
         "viewId": "TaskTest", 
         "viewLevel": 1 
        }, 
        "object": { 
         "viewName": "Object", 
         "viewId": "object", 
         "viewLevel": 2 
        } 
       } 
      } 
     }, 

     init : function() { 
      UIComponent.prototype.init.apply(this, arguments); 

      // Parse the current url and display the targets of the route that matches the hash 
      this.getRouter().initialize(); 
     } 

    }); 
} 

)。

_showObjectでこの値:

f {mEventRegistry: Object, oView: f}

どのようにこのエラーを修正するには?

+1

BaseControllerクラスを定義し、それを使用して他のコントローラを定義することができます。 SAPUI5の例にはこの基本コントローラがあります。そしてそこにはgetRouterメソッドが定義されています。あなたはその部分を欠いている。 – Huseyin

答えて

1

​​ をお試しください

getRouter関数で今持っているものの代わりに。

0

onPress : function(oEvent) { 
    var oRouter = sap.ui.core.UIComponent.getRouterFor(this); 
    oRouter.navTo("object", { 
    objectId: 
    oEvent.getSource().getBindingContext().getProperty("task_id") 
}); 

を試してみましたが、それが働いています。

REF:https://openui5.hana.ondemand.com/#docs/guide/e5200ee755f344c8aef8efcbab3308fb.html


を@hdereliのおかげで、私はヘルパーを含めるのを忘れ:BaseController.js

getRouter : function() { return sap.ui.core.UIComponent.getRouterFor(this) },

関連する問題