在SAPUI5中实例化片段时传递另一个控制器

nja*_*mes 6 javascript controller fragment sapui5

在SAPUI5/OpenUI5 xmlfragment文档中,第三个参数是用于处理片段中的操作的控制器.

这对于按下按钮等的对话框片段至关重要.

大部分时间我都看到过这个实例化为thissap.ui.getCore().byId('<element>').getController())

请参阅Fragment中的示例未获得正确的Controller

由于特定对话框的复杂性,我希望有一个单独的控制器.

我已经环顾四周并进行了一些尝试,但到目前为止还没有成功.

我已经在github上使用了一个工作示例this.

但我想实例Dialog.js化为Dialog.fragment.xmlfrom 的控制器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();

}
Run Code Online (Sandbox Code Playgroud)

});

谢谢.

qma*_*cro 2

(刚到SYD机场)

你所缺少的只是

jQuery.sap.require("sc.test.view.Dialog");
Run Code Online (Sandbox Code Playgroud)

在你的initial.controller.js

将分支中的快速修复推送到您的存储库并打开PR