3 weeks ago
Hi,
I have UI5 application that executes a GET request and returns the data to the UI as a JSONModel. I'm trying to iterate through the results to get to the data I want but am having challenges.
Below is a sample of the data with just 2 results. I'm trying to get to the oData section and I'm obviously not doing it right.
Interesting that in the Dev Tools of Chrome, it appears a little differently, showing the indexes of the array rows in oData. I put a screen shot below the JSONModel data.
Any ideas and/or suggestions anyone has would be greatly appreciated.
Thanks in advance!
Ron
***********************************************************************
JSONModel data:
{
"pSequentialImportCompleted": {},
"mEventRegistry": {},
"mMessages": {},
"id": "id-1713560453764-17",
"aBindings": [],
"oBindingsToRemove": {},
"mContexts": {},
"oData": [
{
"pipelinerunseq": 20547673299878010,
"starttime": "2024-03-05T13:05:38.693Z",
"stoptime": "2024-03-05T13:06:49.992Z",
"stagetype": "CompensateAndPay",
"status": "Successful",
"command": "PipelineRun",
"period": "June 2022",
"numerrors": 0,
"numwarnings": 2,
"time": "13:05",
"daydate": "05"
},
{
"pipelinerunseq": 20547673299878010,
"starttime": "2024-03-05T13:07:21.975Z",
"stoptime": "2024-03-05T13:08:04.098Z",
"stagetype": "CompensateAndPay",
"status": "Successful",
"command": "PipelineRun",
"period": "June 2022",
"numerrors": 0,
"numwarnings": 2,
"time": "13:07",
"daydate": "05"
}
],
"sDefaultBindingMode": "TwoWay",
"bDestroyed": false,
"bLegacySyntax": false,
"sRemoveTimer": null,
"iSizeLimit": 100,
"mSupportedBindingModes": {
"OneWay": true,
"TwoWay": true,
"OneTime": true
},
"mUnsupportedFilterOperators": {
"Any": true,
"All": true
},
"sUpdateTimer": null,
"bCache": true,
"aPendingRequestHandles": []
}
What shows in Dev Tools:
So here's something odd. When I use const oDataArray = oDrdModel.oData, I then created an IF statement checking whether oDataArray is an array or not using Array.isArray() and, for whatever reason, it says that it isn't an array.
That has me stumped. I can see that it's an array.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ryan,
The script is ToolPage.controller.js, which controls the ToolPage.view.xml view.
Or are you looking for the exact code? This code retrieves the data shown in Dev Tools:
const oDtdModel = new JSONModel("../../rest/catalog/PipelineService");
console.log("oDtdModel: ", oDtdModel);
When I added the code that David suggested right after that, I got the error. I tried a modified version of that code but that brought back something that didn't have the oData array in it.
const oData = oDtdModel.getData();
console.log("oData: ", oData);
The oData array of the one that shows everything in Dev Tools has 30 items in it, which is what I'm trying to get to.
I hope that answered your question, Ryan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ron,
Change the following (it will only work if that is how you are already retrieving your model successfully) :
const oDtdModel = new JSONModel("../../rest/catalog/PipelineService");
console.log("oDtdModel: ", oDtdModel);
To:
const oDtdModel = new JSONModel("../../rest/catalog/PipelineService").getData();
console.log("oDtdModel: ", oDtdModel);
Regards,
Ryan Crosby
Hi Ron,
like this ?
let oData = this.getView().getModel("oDtdModel").getData();
This should give you your data as array, as seen in the dev tools.
Best regards,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.