从视图中删除控件
Remove a Control from View
我正在尝试在运行时创建一个 sap.m.Text 并删除创建的元素。创建很简单,但删除元素是个问题。我找不到办法。
代码:
创建
新 sap.m.Text(this.createId("Row1"))
移除
_oThis.getView().removeContent(1); // Doesn't work
_oThis.getView().removeContent(oObjText); // Doesn't work
_oThis.getView().removeContent(sap.ui.getCore().byId('Row1')); // Doesn't work
_oThis.getView().removeContent(view.byId(oo)); // Doesn't work
_oThis.getView().removeContent('Row1'); // Doesn't work
删除元素的东西os $('Row1').remove(); // 但不会从聚合中删除,如果使用相同的 ID 'Row1'
添加回来,则会出现重复 ID 错误
PS :
$('Row1').remove() 并没有真正起作用,因为它没有从视图对象中删除。如何按 ID 从 JS 视图中删除 Text/Button 或任何控件?
https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.mvc.View.html#removeContent
我在我的本地机器上创建了一个小的本地示例。你有两个选择,要么在创建时检查你的文本控件是否已经存在并做一些调整,要么 - 如果你真的想要一个干净的开始 - 销毁它:
this.byId("Row1").destroy();
请注意,最好使用 createId:
创建标识符
this.createId("Row1");
您可以使用 .destroy<em><aggregationName></em>()
方法删除控件。
例如,sap/f/DynamicPage
有一个名为 <content>
的聚合。 IE。 .destroy<em>Content</em>()
可以使用:
var oDynamicPage = this.byId("dynamicContentForm");
if (oDynamicPage !== undefined) {
oDynamicPage.destroyContent();
}
我正在尝试在运行时创建一个 sap.m.Text 并删除创建的元素。创建很简单,但删除元素是个问题。我找不到办法。
代码:
创建 新 sap.m.Text(this.createId("Row1"))
移除
_oThis.getView().removeContent(1); // Doesn't work
_oThis.getView().removeContent(oObjText); // Doesn't work
_oThis.getView().removeContent(sap.ui.getCore().byId('Row1')); // Doesn't work
_oThis.getView().removeContent(view.byId(oo)); // Doesn't work
_oThis.getView().removeContent('Row1'); // Doesn't work
删除元素的东西os $('Row1').remove(); // 但不会从聚合中删除,如果使用相同的 ID 'Row1'
添加回来,则会出现重复 ID 错误PS : $('Row1').remove() 并没有真正起作用,因为它没有从视图对象中删除。如何按 ID 从 JS 视图中删除 Text/Button 或任何控件?
https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.mvc.View.html#removeContent
我在我的本地机器上创建了一个小的本地示例。你有两个选择,要么在创建时检查你的文本控件是否已经存在并做一些调整,要么 - 如果你真的想要一个干净的开始 - 销毁它:
this.byId("Row1").destroy();
请注意,最好使用 createId:
创建标识符this.createId("Row1");
您可以使用 .destroy<em><aggregationName></em>()
方法删除控件。
例如,sap/f/DynamicPage
有一个名为 <content>
的聚合。 IE。 .destroy<em>Content</em>()
可以使用:
var oDynamicPage = this.byId("dynamicContentForm");
if (oDynamicPage !== undefined) {
oDynamicPage.destroyContent();
}