Skip to Content

Unable to access the model after onInit

  1. I have a model in component.js. I am displaying the data in a view in 'editable input fields' from that model. That model is only called in onInit(). So when I am erasing some field in the input and then navigating back and coming again on the screen, the data is not coming on that screen. I have fetched the data in XML. You can also see : StackOverflow link

Code

	onInit: function () {
			this.router = sap.ui.core.UIComponent.getRouterFor(this);

			this.detailModel = sap.ui.getCore().getModel("detailModel");
			this.getView().setModel(this.detailModel, "detailModel");
			this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
		},


		_handleRouteMatched: function (evt) {
			if (evt.getParameter("name") !== "CloneTravelRequest") {
				return;
			}
			
				var that = this;


			//fetching Train Names
			$.ajax({
				url: "/Non_sap_create_requests/odata/TravelPrpTrainDetails",
				method: "GET",
				dataType: "json",
				success: function (data) {
					that.getView().getModel("Model").setProperty("/TravelPrpTrainDetails", data.value);
					var tempModel = that.getView().getModel("detailModel");
					var train = tempModel.getData().TrainName;
					var trainKey = formatter.pickTrainKeyFromModel(data.value, train);
					that.getView().byId("trainName").setSelectedKey(trainKey);
					that.setLocations();
					var nameofPass = tempModel.getData().NameOfPsngr;
					if (nameofPass === "" || nameofPass === null) {
						that.getView().byId("nameOfP").setValue(tempModel.getData().Requestee);
					}
				},
				error: function (err) {
					console.log(err.message);
				
				}
			});
			
			var fdate = new Date();
			this.getView().byId("date").setDateValue(new Date());
			this.getView().byId("date").setMinDate(fdate);
		//	this.onBeforeRendering();
		},
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

0 Answers