gpt4 book ai didi

javascript - _oDialog.destroy() 后出现 "setInitialFocusId"错误

转载 作者:行者123 更新时间:2023-11-30 11:09:40 28 4
gpt4 key购买 nike

在调用 this._oDialog.destroy() 后尝试再次打开 Dialog 片段时,出现以下错误:

Uncaught TypeError: Cannot read property 'setInitialFocusId' of null

我的问题就像此处所述的问题:How to clear dialog/xmlfragment content after close?但是,解决方案显然似乎只是“不要使用属性 setInitialFocus”,我没有在我的代码中的任何地方使用它。

Controller

openDialog: function() {
if (!this._oDialog) {
this._oDialog = sap.ui.xmlfragment("myFragmentPath", this);
this.getView().addDependent(this._oDialog);
}
this._oDialog.open();
},

onExit: function () {
if (this._oDialog) {
this._oDialog.destroy();
}
},

afterClose: function () {
if (this._oDialog) {
this._oDialog.destroy();
}
},

handleClose: function (oEvent) {
this._oDialog.close();
}

对话框片段

<Dialog xmlns="sap.m" afterClose=".afterClose">
<!-- ... -->
</Dialog>

主 XML View

<Button press=".openDialog" />

附加信息:

  • 调用 this._oDialog.open(); 时,Controller 行中出现错误消息。
  • 我使用的是 1.60.1 版 sap 库。

最佳答案

if (this._oDialog) {
this._oDialog.destroy();
this._oDialog = null; // make it falsy so that it can be created next time
}

关闭后,对话框在您的代码中被销毁。 但是, this._oDialog还在那里。

this._oDialog不是虚假值,而只是一个销毁 对话框实例,openDialog() 中没有创建新的对话框第二次。因此,您正试图打开一个被破坏的对话框。

当对话框被销毁时,它的内部 oPopupset to null ,其中解释了错误消息。


⚠️ 注意事项

  1. 关闭后通常不需要销毁对话框。当 View 被销毁时,对话框将自动销毁,因为片段依赖于 View 。如果打算重置数据值,请尝试 unbinding properties而不是每次都销毁并重新创建整个片段,这是非常昂贵的。

  2. 自 UI5 1.56 起,工厂函数 sap.ui.xmlfragment已弃用,因为它通过同步 XHR(阻塞主线程)获取片段。使用 new asynchronous APIs 之一.

  3. 一个更简单的选择是使用 <core:Fragment fragmentName="..." type="XML" /> 在您的 View 定义中以声明方式添加片段<dependents>某种控制的聚合。 Like in this sample .

关于javascript - _oDialog.destroy() 后出现 "setInitialFocusId"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54214764/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com