on 2021 Dec 06 9:51 AM
Hi all,
I want to auto refresh my UI5 Project. Here is my code from an other question in a controller. sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("DurchstichSYS.DurchstichSYS.controller.refresh", {
[window.]setInterval(functionToRefreshModel,1000); //Trigger this function every 1000 milliseconds
}
});
});
I get a error like "parsing error unexpected token". Please help me.
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("DurchstichSYS.DurchstichSYS.controller.Durchstich", {
onBeforeRendering: function () {
setInterval(function () {
this.location.reload(true);
// sap.ui.getCore().byId("Durchstich").getModel("").refresh(true);
}, 10000);
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you'd better learn some basic javascript, what you are asking has nothing to do with ui5.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, this message is correct as you cannot enter arbitrary JavaScript code within an object. Have a look here to see what the expected syntax of a UI5 controller is. You probably want to call setInterval in the onInit method of the controller.
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("sap.ui.demo.walkthrough.controller.App", {
onInit: function () {
setInterval(functionToRefreshModel, 1000); //Trigger this function every 1000 milliseconds
}
});
});
I also should mention that using setInterval to refresh a model smells a bit like an anti pattern.
PS: Please make use of the code formatter next time you ask a question. This makes it easier to read and answer your question 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's stay in English here so that non-German speakers can follow the discussion as well 🙂
This approach is ok if you do it carefully. But you need to make sure the interval is only initialized once and to clear it when the controller is destroyed.
And yes, you need to implement that function as well. It's up to you where you define it but I needs to be in scope of the onInit function. This is a pure JS question and not related to the UI5 framework.
Thank you for the answer! I get again the error with the unexcpected token.
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("DurchstichSYS.DurchstichSYS.controller.Durchstich", {
onInit: function () {
setInterval( functionToRefreshModel , 1000 ); // Diese Funktion alle 1000 Millisekunden auslösen
functionToRefreshModel{
DurchstichSYS.DurchstichSYS.view.Durchstich.reload();
}
}
});
});
function functionToRefreshModel(){
DurchstichSYS.DurchstichSYS.view.Durchstich.reload();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I still get a Parsing error: unexpected token fuction [ESLINT: () ]
jun.wu5
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("DurchstichSYS.DurchstichSYS.controller.Durchstich", {
onInit: function () {
// falsches event
[window].setInterval(functionToRefreshModel , 1000 ); // Diese Funktion alle 1000 Millisekunden auslösen
}
function functionToRefreshModel(){
DurchstichSYS.DurchstichSYS.view.Durchstich.reload();
}
}
});
});
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("DurchstichSYS.DurchstichSYS.controller.Durchstich", {
onInit: function () {
function functionToRefreshModel(){
DurchstichSYS.DurchstichSYS.view.Durchstich.reload();
}
// falsches event
[window].setInterval(functionToRefreshModel , 1000 ); // Diese Funktion alle 1000 Millisekunden auslösen
}
}
});
});
User | Count |
---|---|
62 | |
12 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.