sapui5演练step19重用对象问题

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (55)

根据文档,我构建了自己的对象,我想在对话框控制器nestedviewcontroller.controller.js中重用

    sap.ui.define([
   "sap/ui/core/mvc/Controller",
   "sap/m/MessageToast",
   "sap.ui.demo.walkthrough.controller.Dialog"
    ], function (Controller, MessageToast, Fragment,Dialog) {
   "use strict";
    return 
    Controller.extend("sap.ui.demo.walkthrough.controller.NestedController", 
    {

       ...,

          onOpenDialog : function () {
            // set dialog
            var oView = this.getView();
            var myDialog = new Dialog(oView);
            myDialog.open();

          },

          onCloseDialog : function () {
            this.byId("Dialog").close();
            }
       });
    });

错误消息:未捕获(在promise中)错误:无法从resources / sap.ui.demo.walkthrough.controller.Dialog.js加载sap.ui.demo.walkthrough.controller.Dialog.js:404 - 资源可能进入代码在这里找不到!

提问于
用户回答回答于

:未捕获的TypeError:对话框不是f.onOpenDialog的构造函数(NestedController.controller.js?eval:22)

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

    return ManagedObject.extend("sap.ui.demo.walkthrough.controller.Dialog", {

        constructor : function Dialog(oView) {
            this._oView = oView;
        },

        exit : function () {
            delete this._oView;
        },

        open : function () {
            var oView = this._oView;

            // create dialog lazily
            if (!oView.byId("Dialog")) {
                var oFragmentController = {
                    onCloseDialog : function () {
                        oView.byId("Dialog").close();
                    }
                };
                // load asynchronous XML fragment
                Fragment.load({
                    id: oView.getId(),
                    name: "sap.ui.demo.walkthrough.view.Dialog",
                    controller: oFragmentController
                }).then(function (oDialog) {
                    // connect dialog to the root view of this component (models, lifecycle)
                    oView.addDependent(oDialog);
                    oDialog.open();
                });
            } else {
                oView.byId("Dialog").open();
            }
        }

    });

});

扫码关注云+社区

领取腾讯云代金券