on 2018 Nov 02 1:10 PM
Hi there
I'm wondering if there's an elegant solution to my problem. I need to have a "Refresh" button in my UI5 app and I don't want to reload the app. All the data are bound to local JSON models, defined in Manifest.json and the initial data are in a .json file:
Manifest.json:
...
"dataSources": {
"Model1": {
"uri": "model/Model1.json",
"type": "JSON" },
...
"models": {
"Model1": {
"type": "sap.ui.model.json.JSONModel",
"dataSource": "Model1"
},
...
Then, in my model/Model1.json file I have my initial data:
model/Model1.json:
{
"Field1": "value1",
"Field2": "value2"
}
When the app starts, the model works fine and the initial data is there.
In my app, "Field1" is changed to "valueA" using the setProperty() method, while "Field2" is changed to "valueB" using binding. Now, in my refreshModel() function, I want to "reset" the values of "Field1" and "Field2" to their initial values ("value1" and "value2"). I've gone through most of the methods available to sap.ui.model.json.JSONModel, but can't find a way to do it.
For the moment, I have this in my view controller:
refreshModel: function(oModel1){
oModel1.setProperty("/Field1", "value1";
oModel1.setProperty("/Field2", "value2";
}
This works fine, but I've a lot of entries and it's a bit tedious if I change the initial values or add/remove fields.
Is there a better way of "resetting" the model?
Any help appreciated,
Thomas
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Thanks for getting back to me.
mariusobert's solution did not work for me as it expect a Javascript file.
I ended up with the solution I tried to avoid, and guess I'll have to live with that...
window.location.reload(true);
Thanks for your input though!
Regards,
Thomas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.