on 02-23-2024 2:45 PM
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:
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
as already pointed out, you didn't fetch the element with that
that.getView().byId("tx1");
Can you share how your view looks like?
Best,
Edrilan Berisha
SAP S/4HANA Cloud Financials Development
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.