on 08-23-2017 11:11 AM
Hi,
I have JSON which is of the following format:
{
"Rowsets":{
"DateCreated":"2017-08-22T17:20:00",
"Version":"15.0 SP4 Patch 8 (Jul 30, 2015)",
"StartDate":"2017-08-22T16:20:00+0530",
"EndDate":"2017-08-22T17:20:00+0530",
"CachedTime":"",
"Rowset":[
{
"Columns":{
"Column":[
{
"Name":"B_CATEGORY",
"SourceColumn":"B_CATEGORY",
"Description":"B_CATEGORY",
"SQLDataType":12,
"MinRange":1.0,
"MaxRange":1.0
}
]
},
"Row":[
{
"B_CATEGORY":"Action"
},
{
"B_CATEGORY":"Fiction"
},
{
"B_CATEGORY":"Romance"
},
{
"B_CATEGORY":"Thriller"
}
]
}
]
}
}
And the following is the controller:
onInit: function(evt) {
var oModel = new sap.ui.model.json.JSONModel("firstsapui5project/data.json");
this.getView().setModel(oModel);
}
I want to access all B_CATEGORY values in the select box and I use the below code for it
<Select id="selStaff" items="{/Row}" change="handleStaffSelect">
<core:ListItem key="{B_CATEGORY}" text="{B_CATEGORY}" />
</Select>
It doesn't work. I think there's some problem with this - items="{/Row}. Can anyone please help?
"{/Rowsets/Rowset/0/Row}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Loop through the local oModel in debugger console(while in action).
Here, you can loop through the possible methods to identify the exact path to the B_Category field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the issue is with the path... you need to name it using the correct path, something like this may work for your items: "{Rowsets/RowSet/Row}" but you may still have an error bc of the nested arrays. Alternatively, please move the Row property at the first level:
{
Rowsets:{},
Rows: [] // something like this
}
and your current code should work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried {Rowsets/RowSet/Row} earlier but like you said, it didn't work. Actually the system I am working on (MII) gives the output in JSON I have included in the question. It automatically includes those lines -
"Rowsets":{
"DateCreated":"2017-08-22T17:20:00",
"Version":"15.0 SP4 Patch 8 (Jul 30, 2015)",
"StartDate":"2017-08-22T16:20:00+0530",
"EndDate":"2017-08-22T17:20:00+0530",
"CachedTime":"",
"Rowset":[
{
"Columns":{
"Column":[
{
"Name":"B_CATEGORY",
"SourceColumn":"B_CATEGORY",
"Description":"B_CATEGORY",
"SQLDataType":12,
"MinRange":1.0,
"MaxRange":1.0
}
]
},
Can this data be accessed somehow or the initial lines be trimmed?
iterate thru the Rowsets/Rowset array, if one of the items is Row, then you get the list.
var oTmp = yourJSONResponse;
var rowSet = oTmp.Rowsets.Rowset; // assume you have Rowsets and a Rowset
var row = rowSet[0] ? rowSet[0].Row || [] : []; // since you won't have multiple lists, right?
then bind row as your data model
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.