Hello Community experts,
I have a sap.ui.table.Table that is bound to JSONModel retrieved from an odata read call. One of the columns in the table needs to be dynamically generated after the oModel read call completes so that I can traverse through the array returned from it, build a VBox of sap.m.Text controls and fill it with data received in the array. (I can't this do this with binding because I need to fetch data from multiple different arrays returned in the odata call). The issue is, I can't use methods like onBefore or onAfterRendering because of the asynchronous nature of the odata call as the data is undefined still when those get executed. I have tried using the attachRequestCompleted method to try to do it there, but it doesn't render the content I am adding. Here is the method code in the onInit() method of the controller.
this._oModel.attachRequestCompleted(function(oEvent) {
var oView = this.getView();
var oData = this._oData; // from the oModel.read() call
var commentsSection = oView.byId("commentsVBox");
commentsSection.insertItem(new sap.m.Text({
text: oData.results[0].comment
}));
}, this);
I've tried the above code in all 3 methods; onInit(), onBeforeRendering() and onAfterRendering(). None of these worked. So far for testing i just inserted on Text item, but the plan was to iterate an array and inserts as many per line item as needed. Does anyone know how I may achieve this? Is this the wrong way to go about it?
Thanks,
D
Request clarification before answering.
Hi dngo,
try to use the model to bind text elements like this:
<VBox items="{/MyItems}">
<items>
<Text text="{mytext}"/>
<items>
</VBox>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Thorsten,
Thanks for the response. I cannot use binding (or can't think of a way it would work in my scenario), because the data comes from multiple nested arrays that I need to iterate through first. What I am trying is then adding the sap.m.Text ui controls to the ui after the odata call is made depending on the amount of line items returned in the nested arrays.
D
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.