“出口"在哪里?方法从何而来?它在哪里记录? [英] Where does the "exit" method come from? Where is it documented?

查看:54
本文介绍了“出口"在哪里?方法从何而来?它在哪里记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注关于第 19 步:重用对话框的演练教程.在下面的代码中,我无法弄清楚 exit 方法的来源.我在 ManagedObject 的 API 参考 中找不到任何内容.

I've been following the walkthrough tutorial on Step 19: Reuse Dialogs. In the code below, I cannot figure out where the exit method comes from. I could not find anything in the API reference for ManagedObject.

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

  return ManagedObject.extend("sap.ui.demo.walkthrough.controller.HelloDialog", {
    constructor: function(oView) {
      this._oView = oView;
    },
    exit: function () {
      delete this._oView;
    },
    open: function() {
      // ...
    }
  });
});

如果 API 参考中没有记录,那么有人怎么知道 exit 可以覆盖,更重要的是,为什么不覆盖 destroy 而不是 >退出?类似的东西:

If it is not documented in the API reference, how would someone know that exit is available to override and, more importantly, why not override destroy instead of exit? Something like:

  // ...
  return ManagedObject.extend("sap.ui.demo.walkthrough.controller.HelloDialog", {
    constructor: function(oView) {
      this._oView = oView;
    },
    destroy: function() {
      delete this._oView;
      ManagedObject.prototype.destroy.apply(this, arguments);
    },
    open: function() {
      // ...
    }
  });
});

推荐答案

钩子方法 exit 记录在 ManagedObject 的子类 sap.ui.core.Element: https://openui5.hana.ondemand.com/api/sap.ui.core.Element#methods/exit

The hook method exit is documented in ManagedObject's subclass sap.ui.core.Element: https://openui5.hana.ondemand.com/api/sap.ui.core.Element#methods/exit

用于在销毁前清理元素实例的钩子方法.应用程序不能直接调用这个钩子方法,当元素被销毁时由框架调用.
Element 的子类应覆盖此钩子以实现任何必要的清理.

Hook method for cleaning up the element instance before destruction. Applications must not call this hook method directly, it is called by the framework when the element is destroyed.
Subclasses of Element should override this hook to implement any necessary cleanup.

exit: function() {
   // ... do any further cleanups of your subclass e.g. detach events...

   if (Element.prototype.exit) {
       Element.prototype.exit.apply(this, arguments);
   }
}

关于如何使用退出钩子的更详细描述,请参见部分exit() 方法在文档中.

For a more detailed description how to to use the exit hook, see Section exit() Method in the documentation.

sap.ui.base.Object >.EventProvider >.ManagedObject >sap.ui.core.Element >.Control >...

sap.ui.base.Object > .EventProvider > .ManagedObject > sap.ui.core.Element > .Control > ...

为什么不重写destroy?";好吧,演练没有解释的一件事是开发 UI5 内容时主要有两个角色:

"Why not override destroy instead?" Well, one thing that the walkthrough doesn't explain is that there are mainly two roles when developing UI5 content:

  • 控制-/框架-提供应用程序开发平台的开发者
    → 覆盖 protected 方法,例如 exit.
  • 以及纯粹使用高级控件和 API 的应用程序开发人员.
    → 应该只调用 public 方法,例如 destroy 如果不再需要控件.
  • Control-/ framework-developer who provides a platform for application development
    → Overrides protected methods, such as exit.
  • And application developer who purely consumes high level controls and APIs.
    → Should call public methods only, such as destroy if the control is no longer needed.

在第 19 步中,通过扩展诸如 ManagedObject 之类的低级类,您跨越了应用开发者的角色,并为应用开发者提供了一个 hook 方法,他们将调用 myHelloDialog.destroy().

In step 19, by extending a low-level class such as ManagedObject, you're crossing the app developer role and providing a hook method for app developers who would call myHelloDialog.destroy().

这篇关于“出口"在哪里?方法从何而来?它在哪里记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆