在 SAPUI5/OpenUI5 xmlfragment documentation第三个参数是一个 Controller ,用于处理片段中的操作。
这对于包含要按的按钮等的对话框片段非常重要。
大多数时候我看到它被实例化为 this
或 sap.ui.getCore().byId('<element>').getController())
请参阅 Fragment not get correct Controller 中的示例
由于特定对话框的复杂性,我希望有一个单独的 Controller 。
我环顾四周并进行了几次尝试,但到目前为止没有成功。
我在 github 上放了一个工作示例使用 this
.
但我想实例化Dialog.js
作为 Dialog.fragment.xml
的 Controller 来自 initial.view.controller
有人要吗?
很高兴收到拉取请求。
示例的关键如下(这是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();
}
});
谢谢。
最佳答案
(刚到SYD机场)
你所缺少的只是
jQuery.sap.require("sc.test.view.Dialog");
在你的 initial.controller.js
中。
将分支中的快速修复推送到您的存储库并打开 PR
关于javascript - 在 SAPUI5 中实例化片段时传递另一个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27095330/