on 09-28-2018 9:36 AM
Hi, I have a created a default model and when I start my application, I want to copy it to a second model and then use it in a different function to reset everything. Here what I have done, on my InitFunction:
console.log("Data ", data);
copyModel = $.extend({}, data);
Data is my original model. I have declared the copyModel as a global variable.
Then I have the resetFunction:
resetP: function(){
this.getView().setModel(new JSONModel(copyModel));
console.log("CopyModel ", copyModel);
}
The code seems to run, but I have a weird problem. When I first click the reset Button, copyModel is same with the original model (data). The second time I ran the resetFunction, copyModel is not the same with the original. It has been overwritten with the existing one the moment I press the button. Can anyone help me with that? Thank you!
Unfortunately, none of these two ways worked. As it's written on Stackoverflow and works for me:
resetP: function(){
this.getView().getModel().updateBindings();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try cloning the original object like this instead of the $.extend function
var copyObject = JSON.parse(JSON.stringify(originalObject));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't understand really well what are you trying to ask...
But I'm gonna play... I think that the problem is in new JSONModel:
this.getView().setModel(new JSONModel(copyModel));
What is DATA? Json model? oData Model?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, data is my original JSON model from a form which is being created when I first open my app. I want to have a copy of this model for using it when I am resetting my form. The problem is that at first I keep a right copy and when I run the reset function for a second time, the copy of the model is changed.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.