cancel
Showing results for 
Search instead for 
Did you mean: 

setText doesn't work in attachRequestCompleted

UlisesCasal
Explorer
0 Kudos

Hello everyone!!, I’m developing in sapui5 and I want to be able to setText to an element of my View, but when I run it, it gives me the following error:

UlisesCasal_0-1708699381855.png

The code below:

_onObjectMatched: function(oEvent) {
			var oModel = new JSONModel(
				sap.ui.require.toUrl("Ejercicio1Tabla/jg.json")
			);
			this.getView().setModel(oModel, "jg");

			var cc = oEvent.getParameter("arguments").equipo1;
			var cc1 = oEvent.getParameter("arguments").equipo2;
			var textId1 = this.getView().byId("tl");
			var strTitle = 'Jugadores del encuentro ' + cc + ' VS ' + cc1;
			textId1.setText(strTitle);
			var jugadores = [];
			var that = this;
			oModel.attachRequestCompleted(function() {
				var data = oModel.getData();

				data.jg.forEach(function(partido) {
					if (partido.local === cc && partido.visitante === cc1) {
						jugadores.push(partido.jugador1);
						jugadores.push(partido.jugador2);
						jugadores.push(partido.jugador3);
					}
				});
				var txtJugadores = that.getView().byId("tx1");
				txtJugadores.setText(jugadores);
			});

		}

Regards

Ryan-Crosby
Active Contributor
0 Kudos
You need to check the result on line 24 because it indicates that txtJugadores is undefined. You cannot call a method setText on an undefined object.
View Entire Topic
Edrilan_Berisha
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

 

what exactly do you try to achieve here? You want to bind the table, no? If so then what you try to do is not correct.

You should bind the table with the data you get from some backend OData service for instance.

 

 

<Text id="tx1" text="{jg>/items}"/> 

 

 

You should not set the text of each column and row yourself with the setText() method. This is not how the setText() method was intended to be used.

 

You should read into the topic of binding sap.m.table, there are also questions already and blogs about this topic in this community.

https://community.sap.com/t5/technology-q-a/how-to-bind-json-model-to-sap-ui5-m-table/qaq-p/11896079

 

Best,

Edrilan Berisha

SAP S/4HANA Cloud Financials Development