框架:SAPUI5
版本:1.65.6
IDE:网络
我的代码可以工作,但是根据IDE可能不正确,Web-Ide返回错误:
location.reload()不允许。(sap-no-location-reload)
[ESLINT:(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(){
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>
为了重现,您可以直接从SAPUI5应用程序中复制WebIde创建模板中的代码。
location.reload();
,我想知道它们是否是在SAPUI5中执行相同操作的正确方法(通过正确的方法,我的意思是不返回ESLINT错误) location.reload();
在控制器上的onPressRefresh中,它们仅是更多代码,您可以通过在Web端通过简单的复制来重现问题这样做的原因是完全不进行刷新是正确的方法。如果您想忽略该错误,
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();
}
});
});
感谢您的答复,在最小的工作示例中,这仅包含日期,但我希望重新加载<Page>的大部分<content>,这将从模型和后端进行绑定
那为什么不刷新模型呢?
@Erch我会考虑的,谢谢