在SAPUI5 / OpenUI5 xmlfragment documentation中,第三个参数是一个控制器,用于处理片段中的操作。
这对于按下按钮的对话框片段至关重要。
我大部分时间都将此实例化为this
或sap.ui.getCore().byId('<element>').getController())
请参阅Fragment not get correct Controller
上的示例由于特定对话框的复杂性,我希望有一个单独的控制器。
我已经环顾四周并尝试了一些尝试,但到目前为止还没有成功。
我在使用this
的{{3}}上放了一个工作示例。
但我想将Dialog.js
作为Dialog.fragment.xml
的控制器实例化initial.view.controller
任何参赛者?
很高兴收到拉请求。
示例的Crux如下(这是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();
}
});
感谢。
答案 0 :(得分:2)
我能找到的靠近你的例子是在材料短缺Fiori应用程序
oCtrl = sap.ui.controller("myapp.fragments.DirectCallDialog");
oDirectCallDialog = sap.ui.xmlfragment("myapp.fragments.DirectCallDialog", oCtrl);
从helper类调用片段时注入控制器的大量示例。辅助类促进重用,例如,可以从多个视图/组件调用相同的对话框片段。从控制器中调用对话框设置的辅助类方法,并将oController参数设置为&#39; this&#39;。
HTH JSP
答案 1 :(得分:1)
我复制了一个现有的controller.js,并将其重命名。
然后,将其实例化为下面的内容,然后将其传递给片段。
var oNewController = new sap.ui.core.mvc.Controller(“myProject.DialogController”); this._oDialog = sap.ui.xmlfragment(“myPopup”,“myProject.fragments.myPopup”,oNewController);
所有事件现在都在oNewController中处理,而不是之前使用的“this”......
答案 2 :(得分:1)