on 07-13-2023 9:04 AM
Hi, I am doing a read operation and then trying to set the text of sap.m.Text control dynamically from Controller file. The read operation is triggered by the press of a Read button.
I am able to retrieve the data(from northwind service) but no luck setting the Text properly.
This is the Text control and Read Button.
this is controller code in a file.
Do I need to use another method for this?
Thank you.
this is not defined in the success handler. you need to save it in a global var:
var that = this;
....
success:
....
that.getView().byId("t1").setText(textData);
....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The oModel2.read(...) is asynchronous. So the setText(textData) is done before the success function is called.
If you move this.getView().byId("t12).setText(textData) to the success function it should work as expected.
I would prefer to set the text of the text control by a binding.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, i already tried writing the setText() line inside success, but it is giving another error = "Cannot read properties of undefined (reading 'getView')", So i made a variable outside success and then set the ProductName to this variable, but that seems to be not working due to the async behavior. Isnt' there a way to assign the data, once the success executes, like metadataLoaded().
User | Count |
---|---|
77 | |
11 | |
10 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.