环境:
框架:SAPUI5
版本:1.65.6
IDE:
问题:
我的代码可以工作,但是根据IDE,可能不是以正确的方式,Web返回错误:
不允许使用
location.reload()。(sap-无位置-重新装载)
ESLINT:(sap-无位置-重新装载)
代码(最少可复制):
控制员:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], function (Controller, JSONModel) {
"use strict";
return Controller.extend("namespace.controller.App", {
onInit: function () {
this.getView().setModel(new JSONModel({
actualizationDate: new Date()
}), "frontEnd");
},
onPressRefresh: function(){
location.reload();
}
});
});意见如下:
<mvc:View
controllerName="namespace.controller.App"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Shell id="shell">
<App id="app">
<pages>
<Page id="page" title="{i18n>title}">
<content>
<Label text="{i18n>lastActualizedDateTime}" labelFor="lastActualizedTime" class="sapUiSmallMarginEnd"/>
<DateTimePicker
id="lastActualizedTime"
value="{path: 'frontEnd>/actualizationDate'}"
valueFormat="yyyy-MM-dd HH:mm:ss"
displayFormat="yyyy-MM-dd HH:mm:ss"
enabled="false"/>
<Button icon="sap-icon://refresh" type="Transparent" press="onPressRefresh"/>
</content>
</Page>
</pages>
</App>
</Shell>
</mvc:View>为了复制,您可以直接复制通过WebIde中的代码,从SAPUI5应用程序创建模板。
备注:
我知道代码与
location.reload();一起正常工作,我想知道它们是否是在SAPUI5中做同样的正确方法(我的正确意思是不返回ESLINT错误)在控制器上的onPressRefresh中,它们是更多的代码,只是为了让您能够通过web-ide中的简单副本来重现问题。发布于 2020-02-06 09:12:58
这背后的理由是,在他们的皮毛是正确的方式,硬刷新是根本不做它。如果你想忽略这个错误,
location.reload(); // eslint-disable-line sap-no-location-reload但是,如果刷新的唯一原因是刷新日期,请按以下方式重写:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], function (Controller, JSONModel) {
"use strict";
return Controller.extend("namespace.controller.App", {
onInit: function () {
this.getView().setModel(new JSONModel({
actualizationDate: new Date()
}), "frontEnd");
},
onPressRefresh: function(){
this.refreshDate();
},
refreshDate: function(){
const oModel = this.getView().getModel("frontEnd");
oModel.setProperty("/actualizationDate", new Date();
oModel.updateBindings();
}
});
});发布于 2022-09-02 14:08:52
如果要在同一位置重新加载页面,则错误清除方式如下。
window.open(window.document.URL, "_self")https://stackoverflow.com/questions/60077469
复制相似问题