【发布时间】:2014-11-23 22:46:25
【问题描述】:
在SAPUI5/OpenUI5xmlfragment documentation中第三个参数是一个控制器,用于处理来自片段的动作。
这对于需要按下按钮等的对话框片段至关重要。
大多数时候我看到它被实例化为this 或sap.ui.getCore().byId('<element>').getController())
在Fragment not get correct Controller查看示例
由于特定对话框的复杂性,我想为其设置一个单独的控制器。
我已经环顾四周并进行了几次尝试,但到目前为止还没有成功。
我在github 上放置了一个使用this 的工作示例。
但我想将 Dialog.js 实例化为来自 initial.view.controller 的 Dialog.fragment.xml 的控制器
有接受者吗?
很高兴收到拉取请求。
例子的症结如下(这是initial.controller.js):
sap.ui.controller("sc.test.view.initial", {
oDialog: null,
openTestDialog: function(){
console.log("in open dialog");
// instantiate the other controller
var oDialogController = new sc.test.view.Dialog();
// this next commented line is the 'normal' way to do it
// oDialog = new sap.ui.xmlfragment( "sc.test.view.Dialog", this); //oDialogController);
// this is what I would like to achieve
oDialog = new sap.ui.xmlfragment( "sc.test.view.Dialog", oDialogController);
oDialog.open();
},
onCartDialogCancel:function(oEvent){
// this function would then be in the other controller but how to get a handle on the dialog?
oDialog.close();
}
});
谢谢。
【问题讨论】:
-
请也发布您在此处获得的(简化)示例。 (Stackoverflow 政策)
-
谢谢@Gábor-bakos
标签: javascript controller fragment sapui5