on 02-28-2017 10:00 AM
i scenario is i want to show the input value of the View1 in to the View2?
- i have created the json model in the view and stored the input value in to the json model and assigned that json model in to thhe global var.
- in view2 i used that global var.
- But in view2 input box the value is not shoowing i did binding also.
View1 Code:
View1.Controller.js
View2.XMl
View2.controlle.js
hi i tried i got for only one time by placing it in the on init function below code.
now another issue is how to make these code should be called every time before loading the view and how to clear the input field while exiting view2. i tried with the other events also like onbeforerendering and after since they load only one time it not possible to use.
var temp = g_model ;
var oInput = this.getView().byId("InP02");
var temp2 = temp.getData().myValue;
oInput.setValue(temp2);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use sap.m.Router event patternMatched in onInit method of controller (this event will be called every time you come to this view2)
Assuming that route name to navigate to view2 is rtView2
onInit: function() {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("rtView2").attachPatternMatched(this.onRouteMatched, this);
},
onRouteMatched: function(oEvent){
//Write code that needs to be executed when View2 is shown
}
hi i tried use attachPatternMatched and onRouteMatched but it gave error in my program.So i have creted a one More Button as REFRESH and i placed those code in that button press event it worked fine.
Refresh: function(Eevent) {
var temp = g_model;
var oInput = this.getView().byId("InP02");
var temp2 = temp.getData().myValue;
oInput.setValue(temp2);
// console.log(temp.getData().myValue);
},
When you want to access data across two views or more then you should have a common area/memory/model/variable to share the data across all the views.
In your case g_model is set in view1, imagine g_model as a variable.....can you access a variable defined in one file into another file....that is not possible.
Now the next question is where to define model(g_model)? ....we need to identify the root of "view1" and "view2", this root will most probably "Component.js" or "index.html". If you place the model in this root then it can be accessed in all the views.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.